Commit ·
ec34e4a
1
Parent(s): 2af189d
env
Browse files- app/main.py +6 -1
app/main.py
CHANGED
|
@@ -1,6 +1,11 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
|
@@ -18,5 +23,5 @@ def read_root():
|
|
| 18 |
@app.get("/ask")
|
| 19 |
def ask_question(prompt: str):
|
| 20 |
messages = [{"role": "user", "content": prompt}]
|
| 21 |
-
result = pipe(prompt)
|
| 22 |
return result[0]
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
| 4 |
+
from huggingface_hub import login
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Authenticate with Hugging Face
|
| 8 |
+
login(token=os.getenv("HF_TOKEN"))
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
|
|
|
| 23 |
@app.get("/ask")
|
| 24 |
def ask_question(prompt: str):
|
| 25 |
messages = [{"role": "user", "content": prompt}]
|
| 26 |
+
result = pipe(prompt, max_length=200)
|
| 27 |
return result[0]
|