File size: 2,275 Bytes
b609cb7 94793c7 b609cb7 3d46521 b609cb7 3d46521 9280a08 b609cb7 3d46521 b609cb7 0d63998 7cc09ff ebecdfe 7cc09ff a5c49ad ebecdfe 3d46521 ebecdfe 7cc09ff b609cb7 7ff2284 6c0cf80 7ff2284 c6dd373 b609cb7 f275240 b609cb7 ac30ff3 b609cb7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
from gradio_client import Client
from hugchat import hugchat
from hugchat.login import Login
from gtts import gTTS
import json
import gradio as gr
client = Client("https://sanchit-gandhi-whisper-large-v2.hf.space/")
chat_client = Client("https://huggingfaceh4-falcon-chat.hf.space/")
retrieval = Client("https://warlord-k-iiti-similarity.hf.space/")
n_conv = 0
## 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."
init_prompt =""
info="Information: \n"
q_prompt="\n ##Instruction: Please provide an appropriate response to the following: \n"
def change_conv():
# Create a new conversation
id = chatbot.new_conversation()
chatbot.change_conversation(id)
chatbot.chat(init_prompt)
chatbot.cookies = {}
def answer_question(question):
global n_conv
# if(n_conv > 3):
# n_conv = 0
# change_conv(chatbot)
information = retrieval.predict(question, api_name = "/predict")
answer=chat_client.predict(
"Howdy!",
"abc.json",
"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
0.8,
0.9,
fn_index=4
)
n_conv+=1
print(answer)
temp=json.load(open(answer))
print(temp)
return temp
def file_to_text(audio_fpath):
result = client.predict(
audio_fpath,
"transcribe", # str in 'Audio input' Radio component
api_name="/predict"
)
return result
def text_file(text):
tts = gTTS(text, lang = "en")
tts.save("abc.mp3")
return "abc.mp3"
def main(filename):
# text = file_to_text(filename)
# print(text)
answer = answer_question("Can you tell me about IIT Indore, IITIGPT?")
print(answer)
output = text_file(answer)
return output
demo = gr.Interface(main, "audio", "audio")
if __name__ == "__main__":
demo.launch() |