Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +15 -6
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
-
from
|
2 |
-
|
|
|
|
|
3 |
|
4 |
# Create a new FastAPI app instance
|
5 |
app = FastAPI()
|
@@ -7,8 +9,15 @@ app = FastAPI()
|
|
7 |
# Initialize the text generation pipeline
|
8 |
# This function will be able to generate text
|
9 |
# given an input.
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
@app.get("/")
|
14 |
def read_root():
|
@@ -26,7 +35,7 @@ def generate(text: str):
|
|
26 |
can be found [here](<https://huggingface.co/google/flan-t5-small>).
|
27 |
"""
|
28 |
# Use the pipeline to generate text from the given input text
|
29 |
-
output
|
30 |
|
31 |
# Return the generated text in a JSON response
|
32 |
-
return {"output": output[
|
|
|
1 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
2 |
+
repo_id="mistralai/Mistral-7B-Instruct-v0.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 |
# 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():
|
|
|
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=llm_chain.invoke(text)
|
39 |
|
40 |
# Return the generated text in a JSON response
|
41 |
+
return {"output": output["text"]}
|
requirements.txt
CHANGED
@@ -3,4 +3,6 @@ requests==2.27.*
|
|
3 |
uvicorn[standard]==0.17.*
|
4 |
sentencepiece==0.1.*
|
5 |
torch==1.11.*
|
6 |
-
transformers==4.*
|
|
|
|
|
|
3 |
uvicorn[standard]==0.17.*
|
4 |
sentencepiece==0.1.*
|
5 |
torch==1.11.*
|
6 |
+
transformers==4.*
|
7 |
+
langchain-huggingface
|
8 |
+
langchain
|