Fred808 commited on
Commit
624df6b
·
verified ·
1 Parent(s): 11ba705

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -1,9 +1,19 @@
1
  from fastapi import FastAPI, HTTPException
2
  from pydantic import BaseModel
3
  from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
 
 
4
  import torch
5
  import logging
6
 
 
 
 
 
 
 
 
 
7
  # Initialize FastAPI app
8
  app = FastAPI()
9
 
 
1
  from fastapi import FastAPI, HTTPException
2
  from pydantic import BaseModel
3
  from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
4
+ from huggingface_hub import login
5
+ import os
6
  import torch
7
  import logging
8
 
9
+ # Read the Hugging Face token from the environment variable
10
+ token = os.getenv("HUGGING_FACE_HUB_TOKEN")
11
+ if token is None:
12
+ raise ValueError("Hugging Face token not found in environment variables. Please set the HUGGING_FACE_HUB_TOKEN secret in Hugging Face Spaces.")
13
+
14
+ # Log in with the token
15
+ login(token=token)
16
+
17
  # Initialize FastAPI app
18
  app = FastAPI()
19