Add MPT
Browse files
app.py
CHANGED
@@ -1,68 +1,15 @@
|
|
1 |
from gradio_client import Client
|
2 |
-
from hugchat import hugchat
|
3 |
-
from hugchat.login import Login
|
4 |
from gtts import gTTS
|
5 |
import gradio as gr
|
6 |
|
7 |
client = Client("https://sanchit-gandhi-whisper-large-v2.hf.space/")
|
8 |
-
chat_client = Client("https://
|
9 |
retrieval = Client("https://warlord-k-iiti-similarity.hf.space/")
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
init_prompt ="## Instruction: You are an AI language model and must return truthful responses as per the information below\n ##Input: Information: My name is IITIGPT. I am a helpful and truthful chatbot. I can help answer any questions about the IIT Indore campus."
|
14 |
info="Information: \n"
|
15 |
-
q_prompt="\n ##Instruction: Please
|
16 |
-
|
17 |
-
def login_hf():
|
18 |
-
email="jackrudolf584@gmail.com"
|
19 |
-
passwd="Qwertypassword1"
|
20 |
-
|
21 |
-
# login
|
22 |
-
sign = Login(email, passwd)
|
23 |
-
cookies = sign.login()
|
24 |
-
|
25 |
-
# Create a ChatBot
|
26 |
-
chatbot = hugchat.ChatBot(cookies=cookies.get_dict()) # or cookie_path="usercookies/<email>.json"
|
27 |
-
chatbot.chat(init_prompt)
|
28 |
-
|
29 |
-
print("Logged In")
|
30 |
-
return chatbot
|
31 |
-
|
32 |
-
def change_conv():
|
33 |
-
# Create a new conversation
|
34 |
-
id = chatbot.new_conversation()
|
35 |
-
chatbot.change_conversation(id)
|
36 |
-
chatbot.chat(init_prompt)
|
37 |
-
chatbot.cookies = {}
|
38 |
-
|
39 |
-
def answer_question(question):
|
40 |
-
global n_conv
|
41 |
-
if(n_conv > 3):
|
42 |
-
n_conv = 0
|
43 |
-
change_conv(chatbot)
|
44 |
-
information = retrieval.predict(question, api_name = "/predict")
|
45 |
-
answer = chatbot.chat(info+ information +q_prompt+" "+question+"""\n ##Response:""")
|
46 |
-
n_conv+=1
|
47 |
-
return answer
|
48 |
-
|
49 |
-
def _answer(question):
|
50 |
-
information = retrieval.predict(question, api_name = "/predict")
|
51 |
-
answer=chat_client.predict(
|
52 |
-
"Howdy!",
|
53 |
-
"abc.json",
|
54 |
-
"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
|
55 |
-
0.8,
|
56 |
-
0.9,
|
57 |
-
fn_index=4
|
58 |
-
)
|
59 |
-
with open(answer, 'rb') as f:
|
60 |
-
data = f.read()
|
61 |
-
temp=json.load(data)
|
62 |
-
print(temp)
|
63 |
-
return temp
|
64 |
-
|
65 |
-
# chatbot = login_hf()
|
66 |
|
67 |
def file_to_text(audio_fpath):
|
68 |
|
@@ -73,24 +20,35 @@ def file_to_text(audio_fpath):
|
|
73 |
)
|
74 |
return result
|
75 |
|
76 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
tts = gTTS(text, lang = "en")
|
78 |
tts.save("abc.mp3")
|
79 |
return "abc.mp3"
|
80 |
|
81 |
def main(filename):
|
82 |
-
|
83 |
-
print(
|
84 |
-
|
85 |
-
answer = _answer(text)
|
86 |
print(answer)
|
87 |
-
output =
|
88 |
return output
|
89 |
|
90 |
with gr.Blocks() as demo:
|
91 |
with gr.Row():
|
92 |
-
input = gr.Audio(source = "
|
93 |
-
output = gr.Audio(type = "filepath", label = "Output")
|
94 |
btn = gr.Button("Run")
|
95 |
btn.click(main, [input], [output])
|
96 |
|
|
|
1 |
from gradio_client import Client
|
|
|
|
|
2 |
from gtts import gTTS
|
3 |
import gradio as gr
|
4 |
|
5 |
client = Client("https://sanchit-gandhi-whisper-large-v2.hf.space/")
|
6 |
+
chat_client = Client("https://mosaicml-mpt-30b-chat.hf.space/", serialize = False)
|
7 |
retrieval = Client("https://warlord-k-iiti-similarity.hf.space/")
|
8 |
|
9 |
+
init_prompt ="## Instruction: You are an AI language model and must return truthful responses as per the information. Do not answer with any information which isn't completely verified and correct. Do not lie. Do not present information where you don't know the answer. Do not include incorrect extra information. Your name is IITIGPT. You are a helpful and truthful chatbot. You can help answer any questions about the IIT Indore campus."
|
|
|
|
|
10 |
info="Information: \n"
|
11 |
+
q_prompt="\n ##Instruction: Please provide an appropriate response to the following in less than 3 lines: \n"
|
12 |
+
chatbot = [["", None]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def file_to_text(audio_fpath):
|
15 |
|
|
|
20 |
)
|
21 |
return result
|
22 |
|
23 |
+
def answer_question(question):
|
24 |
+
global chatbot
|
25 |
+
information = retrieval.predict(question, api_name = "/predict")
|
26 |
+
answer=chat_client.predict(
|
27 |
+
info +information+question, # str in 'Type an input and press Enter' Textbox component
|
28 |
+
chatbot,
|
29 |
+
fn_index=1
|
30 |
+
)
|
31 |
+
chatbot = answer[1]
|
32 |
+
return answer[1][0][1]
|
33 |
+
|
34 |
+
|
35 |
+
def text_to_file(text):
|
36 |
tts = gTTS(text, lang = "en")
|
37 |
tts.save("abc.mp3")
|
38 |
return "abc.mp3"
|
39 |
|
40 |
def main(filename):
|
41 |
+
question = file_to_text(filename)
|
42 |
+
print(question)
|
43 |
+
answer = answer_question(question)
|
|
|
44 |
print(answer)
|
45 |
+
output = text_to_file(answer)
|
46 |
return output
|
47 |
|
48 |
with gr.Blocks() as demo:
|
49 |
with gr.Row():
|
50 |
+
input = gr.Audio(source = "microphone", type = "filepath", label = "Input")
|
51 |
+
output = gr.Audio(type = "filepath", label = "Output", autoplay = True)
|
52 |
btn = gr.Button("Run")
|
53 |
btn.click(main, [input], [output])
|
54 |
|