Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,12 +3,7 @@ from langchain import PromptTemplate, LLMChain
|
|
3 |
from langchain_huggingface import HuggingFacePipeline, HuggingFaceEndpoint
|
4 |
from transformers import pipeline
|
5 |
import os
|
6 |
-
|
7 |
-
|
8 |
-
# Authenticate with Hugging Face
|
9 |
os.environ["HUGGINGFACEHUB_API_TOKEN"]
|
10 |
-
|
11 |
-
# Load the LLM
|
12 |
pipe = pipeline(
|
13 |
'text2text-generation',
|
14 |
model='google/flan-t5-small',
|
@@ -17,26 +12,21 @@ pipe = pipeline(
|
|
17 |
temperature=0.9
|
18 |
)
|
19 |
llm = HuggingFacePipeline(pipeline=pipe)
|
20 |
-
|
21 |
-
# Define the prompt template
|
22 |
prompt_template = """AI assistant. I am always here to help.
|
23 |
User: {question}
|
24 |
Assistant:"""
|
25 |
prompt = PromptTemplate(template=prompt_template, input_variables=["question"])
|
26 |
-
|
27 |
-
# Create the LLM chain
|
28 |
chain = LLMChain(llm=llm, prompt=prompt)
|
29 |
-
|
30 |
-
# Define the Gradio function
|
31 |
def chatbot(question):
|
32 |
response = chain.run(question)
|
33 |
return response
|
34 |
|
35 |
-
# Create the Gradio interface
|
36 |
demo = gr.Interface(
|
37 |
fn=chatbot,
|
38 |
inputs=gr.Textbox(lines=2, label="Question"),
|
39 |
-
outputs=gr.Textbox(label="Answer")
|
|
|
|
|
40 |
)
|
41 |
|
42 |
# Launch the interface
|
|
|
3 |
from langchain_huggingface import HuggingFacePipeline, HuggingFaceEndpoint
|
4 |
from transformers import pipeline
|
5 |
import os
|
|
|
|
|
|
|
6 |
os.environ["HUGGINGFACEHUB_API_TOKEN"]
|
|
|
|
|
7 |
pipe = pipeline(
|
8 |
'text2text-generation',
|
9 |
model='google/flan-t5-small',
|
|
|
12 |
temperature=0.9
|
13 |
)
|
14 |
llm = HuggingFacePipeline(pipeline=pipe)
|
|
|
|
|
15 |
prompt_template = """AI assistant. I am always here to help.
|
16 |
User: {question}
|
17 |
Assistant:"""
|
18 |
prompt = PromptTemplate(template=prompt_template, input_variables=["question"])
|
|
|
|
|
19 |
chain = LLMChain(llm=llm, prompt=prompt)
|
|
|
|
|
20 |
def chatbot(question):
|
21 |
response = chain.run(question)
|
22 |
return response
|
23 |
|
|
|
24 |
demo = gr.Interface(
|
25 |
fn=chatbot,
|
26 |
inputs=gr.Textbox(lines=2, label="Question"),
|
27 |
+
outputs=gr.Textbox(label="Answer"),
|
28 |
+
title="Chatbot",
|
29 |
+
description="Helpful AI Assistant!!"
|
30 |
)
|
31 |
|
32 |
# Launch the interface
|