PinkAlpaca commited on
Commit
8370716
·
verified ·
1 Parent(s): 26e30fa

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -8
main.py CHANGED
@@ -6,17 +6,16 @@ from transformers import pipeline, TextGenerationPipeline
6
 
7
  app = FastAPI()
8
 
9
- # Get Gemini API key from environment variable (NOT USED FOR HUGGING FACE AUTH)
10
- # gemini_api_key = os.environ.get("GEMINI_API_KEY")
11
- # if not gemini_api_key:
12
- # raise ValueError("GEMINI_API_KEY environment variable is not set.")
13
 
14
- # Load the Gemini model using Hugging Face's pipeline
15
- # Make sure to use a model you have access to and is available on Hugging Face
16
  generator: TextGenerationPipeline = pipeline(
17
  "text-generation",
18
  model="google/gemma-2-2b-it", # The model you want to use
19
- use_auth_token= os.environ.get("TOKEN") # The Hugging Face token you got after login
20
  )
21
 
22
  # Data model for the request body
@@ -44,4 +43,4 @@ async def generate_text(item: Item):
44
  raise HTTPException(status_code=500, detail=f"An error occurred: {e}")
45
 
46
  if __name__ == "__main__":
47
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
6
 
7
  app = FastAPI()
8
 
9
+ # Ensure your Hugging Face token is set as an environment variable
10
+ huggingface_token = os.environ.get("TOKEN")
11
+ if not huggingface_token:
12
+ raise ValueError("TOKEN environment variable is not set.")
13
 
14
+ # Load the model using Hugging Face's pipeline with the token
 
15
  generator: TextGenerationPipeline = pipeline(
16
  "text-generation",
17
  model="google/gemma-2-2b-it", # The model you want to use
18
+ use_auth_token=huggingface_token # Use the Hugging Face token for authentication
19
  )
20
 
21
  # Data model for the request body
 
43
  raise HTTPException(status_code=500, detail=f"An error occurred: {e}")
44
 
45
  if __name__ == "__main__":
46
+ uvicorn.run(app, host="0.0.0.0", port=8000)