Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio_client import Client
|
2 |
+
from hugchat import hugchat
|
3 |
+
from hugchat.login import Login
|
4 |
+
import json
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
chat_client = Client("https://huggingfaceh4-falcon-chat.hf.space/")
|
8 |
+
|
9 |
+
|
10 |
+
retrieval = Client("https://slycat-southampton-similarity.hf.space/")
|
11 |
+
|
12 |
+
n_conv = 0
|
13 |
+
## Instruction: You are an AI language model and must return truthful responses as per the information below\n ##Input: Information: Your name is IITIGPT. You are a helpful and truthful chatbot. You can help answer any questions about the IIT Indore campus."
|
14 |
+
init_prompt =""
|
15 |
+
info="Information: \n"
|
16 |
+
q_prompt="\n ##Instruction: Please provide an appropriate response to the following: \n"
|
17 |
+
|
18 |
+
|
19 |
+
def change_conv():
|
20 |
+
# Create a new conversation
|
21 |
+
id = chatbot.new_conversation()
|
22 |
+
chatbot.change_conversation(id)
|
23 |
+
chatbot.chat(init_prompt)
|
24 |
+
chatbot.cookies = {}
|
25 |
+
|
26 |
+
def main(question):
|
27 |
+
global n_conv
|
28 |
+
# if(n_conv > 3):
|
29 |
+
# n_conv = 0
|
30 |
+
# change_conv(chatbot)
|
31 |
+
information = retrieval.predict(question, api_name = "/predict")
|
32 |
+
answer=chat_client.predict(
|
33 |
+
"Howdy!",
|
34 |
+
"new.json",
|
35 |
+
"You are an AI language model and must return truthful responses as per the information below\n ##Input: Information: Your name is IITIGPT. You are a helpful and truthful chatbot. You can help answer any questions about the IIT Indore campus." +information+question, # str in 'Type an input and press Enter' Textbox component
|
36 |
+
0.8,
|
37 |
+
0.9,
|
38 |
+
fn_index=4
|
39 |
+
)
|
40 |
+
|
41 |
+
|
42 |
+
n_conv+=1
|
43 |
+
print(answer)
|
44 |
+
|
45 |
+
return answer
|
46 |
+
|
47 |
+
|
48 |
+
demo = gr.Interface(main)
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
demo.launch()
|