PrathmeshZ commited on
Commit
430b819
·
1 Parent(s): 7ac1652

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +43 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from langchain import HuggingFaceHub, PromptTemplate, LLMChain
3
+ from langchain.memory import ConversationBufferMemory
4
+
5
+ repo_id = "tiiuae/falcon-7b-instruct"
6
+
7
+ template = """You are a chatbot having a conversation with a human.
8
+
9
+ {chat_history}
10
+ Human: {human_input}
11
+ Chatbot:"""
12
+ prompt = PromptTemplate(template=template, input_variables=["chat_history","human_input"])
13
+
14
+ def generate_response(question, huggingfacehub_api_token, temperature=0.6, max_new_tokens=500):
15
+ memory = ConversationBufferMemory(memory_key="chat_history")
16
+ llm = HuggingFaceHub(huggingfacehub_api_token=huggingfacehub_api_token,
17
+ repo_id=repo_id,
18
+ model_kwargs={"temperature": temperature,
19
+ "max_new_tokens": max_new_tokens})
20
+ llm_chain = LLMChain(prompt=prompt, llm=llm, memory=memory)
21
+ return llm_chain.predict(chat_history="", human_input=question)
22
+
23
+ inputs = [
24
+ gr.inputs.Textbox(label="Question"),
25
+ gr.inputs.Textbox(label="HuggingFace API Token", type="password", default=None),
26
+ gr.inputs.Slider(minimum=0.1, maximum=2.0, default=0.6, label="Temperature"),
27
+ gr.inputs.Slider(minimum=100, maximum=1000, default=500, label="Max New Tokens")
28
+ ]
29
+ outputs = gr.outputs.Textbox(label="Response")
30
+
31
+ title = "Chatbot Interface"
32
+ description = "Provide a question and get helpful answers from the AI assistant."
33
+ examples = [["write a poem on Iron Man"], ["What are the benefits of using Python?"]]
34
+
35
+ iface = gr.Interface(fn=generate_response,
36
+ inputs=inputs,
37
+ outputs=outputs,
38
+ title=title,
39
+ description=description,
40
+ allow_flagging="never",
41
+ examples=examples)
42
+
43
+ iface.launch(share=True, debug=True, show_api=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ langchain
2
+ huggingface_hub
3
+ gradio