|
from gradio_client import Client |
|
from gtts import gTTS |
|
import gradio as gr |
|
|
|
client = Client("https://sanchit-gandhi-whisper-large-v2.hf.space/") |
|
chat_client = Client("https://mosaicml-mpt-30b-chat.hf.space/", serialize = False) |
|
retrieval = Client("https://warlord-k-iiti-similarity.hf.space/") |
|
|
|
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." |
|
info="Information: \n" |
|
q_prompt="\n ##Instruction: Please provide an appropriate response to the following in less than 3 lines: \n" |
|
chatbot = [["", None]] |
|
|
|
def file_to_text(audio_fpath): |
|
|
|
result = client.predict( |
|
audio_fpath, |
|
"transcribe", |
|
api_name="/predict" |
|
) |
|
return result |
|
|
|
def answer_question(question): |
|
global chatbot |
|
information = retrieval.predict(question, api_name = "/predict") |
|
answer=chat_client.predict( |
|
info +information+question, |
|
chatbot, |
|
fn_index=1 |
|
) |
|
chatbot = answer[1] |
|
return answer[1][0][1] |
|
|
|
|
|
def text_to_file(text): |
|
tts = gTTS(text, lang = "en") |
|
tts.save("abc.mp3") |
|
return "abc.mp3" |
|
|
|
def main(filename): |
|
question = file_to_text(filename) |
|
print(question) |
|
answer = answer_question(question) |
|
print(answer) |
|
output = text_to_file(answer) |
|
return None, output |
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# IITI GPT: A Helper Chabot for the Students of IIT Indore which can answer any query related to IIT Indore, or any query in general.") |
|
gr.Markdown("## This is Made by the Students of The Cynaptics Club and The Robotics Club") |
|
gr.Markdown("## See the Robot in Action on LinkedIn of [Robotics Club](https://www.linkedin.com/company/robotics-club-iit-indore/) and [Cynaptics Club](https://www.linkedin.com/company/cynaptics-club-iit-indore)") |
|
with gr.Row(): |
|
input = gr.Audio(source = "microphone", type = "filepath", label = "Input") |
|
output = gr.Audio(type = "filepath", label = "Output", autoplay = True) |
|
btn = gr.Button("Run") |
|
btn.click(main, [input], [input, output]) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |