Spaces:
Runtime error
Runtime error
save
Browse files
app.py
CHANGED
|
@@ -1,26 +1,26 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
## create a new FASTAPI app instance
|
| 5 |
-
app=FastAPI()
|
| 6 |
-
|
| 7 |
-
# Initialize the text generation pipeline
|
| 8 |
-
pipe = pipeline("text2text-generation", model="
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
@app.get("/")
|
| 12 |
-
def home():
|
| 13 |
-
return {"message":"Hello World"}
|
| 14 |
-
|
| 15 |
-
# Define a function to handle the GET request at `/generate`
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
@app.get("/generate")
|
| 19 |
-
def generate(text:str):
|
| 20 |
-
## use the pipeline to generate text from given input text
|
| 21 |
-
output=pipe(text)
|
| 22 |
-
|
| 23 |
-
## return the generate text in Json reposne
|
| 24 |
-
return {"output":output[0]['generated_text']}
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
## create a new FASTAPI app instance
|
| 5 |
+
app=FastAPI()
|
| 6 |
+
|
| 7 |
+
# Initialize the text generation pipeline
|
| 8 |
+
pipe = pipeline("text2text-generation", model="meta-llama/Meta-Llama-3.1-8B-Instruct")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@app.get("/")
|
| 12 |
+
def home():
|
| 13 |
+
return {"message":"Hello World"}
|
| 14 |
+
|
| 15 |
+
# Define a function to handle the GET request at `/generate`
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
@app.get("/generate")
|
| 19 |
+
def generate(text:str):
|
| 20 |
+
## use the pipeline to generate text from given input text
|
| 21 |
+
output=pipe(text)
|
| 22 |
+
|
| 23 |
+
## return the generate text in Json reposne
|
| 24 |
+
return {"output":output[0]['generated_text']}
|
| 25 |
+
|
| 26 |
+
|