Spaces:
Build error
Build error
FIX POST /genereate
Browse filesa GET req will never gonna work to send your query and get the answer
{
"text": "The square root of x is the cube root of y. What is y to the power of 2, if x = 4?"
}
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
app = FastAPI()
|
| 4 |
|
|
@@ -15,18 +16,19 @@ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
|
|
| 15 |
# model = AutoModelForSeq2SeqLM.from_pretrained("ofintech/FinGPT_0.1.3")
|
| 16 |
# pipe = pipeline("text2text-generation", model="MudassirFayaz/llama-2-7b_career_0.6.0", tokenizer=tokenizer)
|
| 17 |
|
| 18 |
-
|
| 19 |
@app.get("/")
|
| 20 |
def home():
|
| 21 |
-
return {"message":"Hello World"}
|
| 22 |
-
|
| 23 |
-
# Define a function to handle the GET request at `/generate`
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
return {"output":output[0]['generated_text']}
|
|
|
|
| 1 |
+
from fastapi import FastAPI,Query
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
from transformers import pipeline
|
| 4 |
app = FastAPI()
|
| 5 |
|
|
|
|
| 16 |
# model = AutoModelForSeq2SeqLM.from_pretrained("ofintech/FinGPT_0.1.3")
|
| 17 |
# pipe = pipeline("text2text-generation", model="MudassirFayaz/llama-2-7b_career_0.6.0", tokenizer=tokenizer)
|
| 18 |
|
|
|
|
| 19 |
@app.get("/")
|
| 20 |
def home():
|
| 21 |
+
return {"message": "Hello World"}
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Define a request model
|
| 24 |
+
class TextRequest(BaseModel):
|
| 25 |
+
text: str
|
| 26 |
|
| 27 |
+
# Define a function to handle the POST request at `/generate`
|
| 28 |
+
@app.post("/generate")
|
| 29 |
+
def generate(request: TextRequest):
|
| 30 |
+
# Use the pipeline to generate text from given input text
|
| 31 |
+
output = pipe(request.text)
|
| 32 |
|
| 33 |
+
# Return the generated text in JSON response
|
| 34 |
+
return {"output": output[0]['generated_text']}
|