File size: 2,535 Bytes
3d21a6e
 
 
 
 
d166f72
3d21a6e
 
d166f72
3d21a6e
d166f72
 
3d21a6e
 
 
 
71ea513
3d21a6e
 
 
 
 
d166f72
 
 
 
 
 
 
 
 
 
 
 
 
3d21a6e
 
 
 
 
d166f72
 
 
3d21a6e
d166f72
4290d03
3d21a6e
de9792d
4290d03
 
 
de9792d
d166f72
 
de9792d
4290d03
3d21a6e
 
 
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
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", # str in 'Audio input' Radio component
        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, # str  in 'Type an input and press Enter' Textbox component
                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()