Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +6 -19
- requirements.txt +0 -2
app.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
-
from
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
llm=HuggingFaceEndpoint(repo_id=repo_id,max_length=128,temperature=0.7)
|
| 5 |
|
| 6 |
# Create a new FastAPI app instance
|
| 7 |
app = FastAPI()
|
|
@@ -9,19 +7,8 @@ app = FastAPI()
|
|
| 9 |
# Initialize the text generation pipeline
|
| 10 |
# This function will be able to generate text
|
| 11 |
# given an input.
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
from langchain import PromptTemplate, LLMChain
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
template = """Question: {question}
|
| 18 |
-
Answer: Let's think step by step."""
|
| 19 |
-
prompt = PromptTemplate(template=template, input_variables=["question"])
|
| 20 |
-
llm_chain=LLMChain(llm=llm,prompt=prompt)
|
| 21 |
-
|
| 22 |
-
@app.get("/")
|
| 23 |
-
def read_root():
|
| 24 |
-
return {"Hello": "World"}
|
| 25 |
|
| 26 |
# Define a function to handle the GET request at `/generate`
|
| 27 |
# The generate() function is defined as a FastAPI route that takes a
|
|
@@ -35,7 +22,7 @@ def generate(text: str):
|
|
| 35 |
can be found [here](<https://huggingface.co/google/flan-t5-small>).
|
| 36 |
"""
|
| 37 |
# Use the pipeline to generate text from the given input text
|
| 38 |
-
output=
|
| 39 |
|
| 40 |
# Return the generated text in a JSON response
|
| 41 |
-
return {"output": output["
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from transformers import pipeline
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Create a new FastAPI app instance
|
| 5 |
app = FastAPI()
|
|
|
|
| 7 |
# Initialize the text generation pipeline
|
| 8 |
# This function will be able to generate text
|
| 9 |
# given an input.
|
| 10 |
+
pipe = pipeline("text2text-generation",
|
| 11 |
+
model="google/flan-t5-small")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Define a function to handle the GET request at `/generate`
|
| 14 |
# The generate() function is defined as a FastAPI route that takes a
|
|
|
|
| 22 |
can be found [here](<https://huggingface.co/google/flan-t5-small>).
|
| 23 |
"""
|
| 24 |
# Use the pipeline to generate text from the given input text
|
| 25 |
+
output = pipe(text)
|
| 26 |
|
| 27 |
# Return the generated text in a JSON response
|
| 28 |
+
return {"output": output[0]["generated_text"]}
|
requirements.txt
CHANGED
|
@@ -4,5 +4,3 @@ uvicorn[standard]==0.17.*
|
|
| 4 |
sentencepiece==0.1.*
|
| 5 |
torch==1.11.*
|
| 6 |
transformers==4.*
|
| 7 |
-
langchain-huggingface
|
| 8 |
-
langchain
|
|
|
|
| 4 |
sentencepiece==0.1.*
|
| 5 |
torch==1.11.*
|
| 6 |
transformers==4.*
|
|
|
|
|
|