Spaces:
Runtime error
Runtime error
Commit
·
619b76c
1
Parent(s):
551cdc9
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from langchain import PromptTemplate, LLMChain
|
3 |
+
from langchain import HuggingFaceHub
|
4 |
+
|
5 |
+
repo_id = "tiiuae/falcon-7b-instruct"
|
6 |
+
llm = HuggingFaceHub(huggingfacehub_api_token=HUGGINGFACE_API_TOKEN,
|
7 |
+
repo_id=repo_id,
|
8 |
+
model_kwargs={"temperature":0.7, "max_new_tokens":700})
|
9 |
+
|
10 |
+
template = """
|
11 |
+
You are a helpful AI assistant and provide the answer for the question asked politely.
|
12 |
+
|
13 |
+
{question}
|
14 |
+
Answer: Let's think step by step.
|
15 |
+
"""
|
16 |
+
prompt = PromptTemplate(template=template, input_variables=["question"])
|
17 |
+
llm_chain = LLMChain(prompt=prompt, llm=llm)
|
18 |
+
|
19 |
+
# Define the function that will be used in Gradio
|
20 |
+
def generate_answer(question):
|
21 |
+
answer = llm_chain.run(question)
|
22 |
+
return answer
|
23 |
+
|
24 |
+
# Create a Gradio interface
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=generate_answer,
|
27 |
+
inputs=gr.inputs.Textbox(),
|
28 |
+
outputs=gr.outputs.Textbox(),
|
29 |
+
title="VSP Bot",
|
30 |
+
description="Created by VSP",
|
31 |
+
)
|
32 |
+
|
33 |
+
# Launch the Gradio interface
|
34 |
+
iface.launch()
|