Update main.py
Browse files
main.py
CHANGED
|
@@ -6,17 +6,16 @@ from transformers import pipeline, TextGenerationPipeline
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
# Load the
|
| 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=
|
| 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)
|