Duplicate from Warlord-K/IITI-GPT
Browse filesCo-authored-by: Yatharth Gupta <[email protected]>
- .gitattributes +35 -0
- README.md +14 -0
- app.py +76 -0
- requirements.txt +4 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: IITI GPT
|
3 |
+
emoji: 💻
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: gray
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.39.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: openrail
|
11 |
+
duplicated_from: Warlord-K/IITI-GPT
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
9 |
+
retrieval = Client("https://warlord-k-iiti-similarity.hf.space/")
|
10 |
+
|
11 |
+
n_conv = 0
|
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 provide an appropriate response to the following: \n"
|
16 |
+
|
17 |
+
def login_hf():
|
18 |
+
email="[email protected]"
|
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 |
+
chatbot = login_hf()
|
50 |
+
|
51 |
+
def file_to_text(audio_fpath):
|
52 |
+
|
53 |
+
result = client.predict(
|
54 |
+
audio_fpath,
|
55 |
+
"transcribe", # str in 'Audio input' Radio component
|
56 |
+
api_name="/predict"
|
57 |
+
)
|
58 |
+
return result
|
59 |
+
|
60 |
+
def text_file(text):
|
61 |
+
tts = gTTS(text, lang = "en")
|
62 |
+
tts.save("abc.mp3")
|
63 |
+
return "abc.mp3"
|
64 |
+
|
65 |
+
def main(filename):
|
66 |
+
text = file_to_text(filename)
|
67 |
+
print(text)
|
68 |
+
answer = answer_question(text)
|
69 |
+
print(answer)
|
70 |
+
output = text_file(answer)
|
71 |
+
return output
|
72 |
+
|
73 |
+
demo = gr.Interface(main, "audio", "audio")
|
74 |
+
|
75 |
+
if __name__ == "__main__":
|
76 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
hugchat
|
2 |
+
gradio
|
3 |
+
gradio_client
|
4 |
+
gtts
|