Spaces:
Runtime error
Runtime error
Commit
Β·
8a9ed1e
0
Parent(s):
Duplicate from fffiloni/whisper-to-chatGPT
Browse filesCo-authored-by: Sylvain Filoni <fffiloni@users.noreply.huggingface.co>
- .gitattributes +34 -0
- README.md +14 -0
- app.py +158 -0
- requirements.txt +3 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Whisper to chatGPT
|
3 |
+
emoji: ππ€
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.15.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
duplicated_from: fffiloni/whisper-to-chatGPT
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
#from pyChatGPT import ChatGPT
|
3 |
+
import os
|
4 |
+
import requests
|
5 |
+
api = os.environ.get('API_ENDPOINT')
|
6 |
+
#session_token = os.environ.get('SessionToken')
|
7 |
+
#cf_clearance_token = os.environ.get('ClearanceToken')
|
8 |
+
#cf_bm_token = os.environ.get('cf_bm_token')
|
9 |
+
whisper = gr.Interface.load(name="spaces/sanchit-gandhi/whisper-large-v2")
|
10 |
+
|
11 |
+
def call_api(message):
|
12 |
+
response = requests.get(f'{api}?q={message}')
|
13 |
+
if response.status_code == 200:
|
14 |
+
|
15 |
+
return str(response.text).split('\n', 2)[2]
|
16 |
+
else:
|
17 |
+
return """Sorry, I'm quite busy right now, but please try again later :)"""
|
18 |
+
|
19 |
+
def chat_hf(audio, task):
|
20 |
+
|
21 |
+
try:
|
22 |
+
whisper_text = translate(audio, task)
|
23 |
+
if whisper_text == "ERROR: You have to either use the microphone or upload an audio file":
|
24 |
+
gpt_response = "MISSING AUDIO: Record your voice by clicking the microphone button, do not forget to stop recording before sending your message ;)"
|
25 |
+
else:
|
26 |
+
gpt_response = call_api(whisper_text)
|
27 |
+
#api = ChatGPT(session_token, cf_clearance_token, cf_bm_token)
|
28 |
+
#api = ChatGPT(session_token)
|
29 |
+
#api.refresh_auth() # refresh the authorization token
|
30 |
+
#if reset_conversation:
|
31 |
+
#
|
32 |
+
# api.reset_conversation() # reset the conversation
|
33 |
+
#resp = api.send_message(whisper_text)
|
34 |
+
#gpt_response = resp['message']
|
35 |
+
|
36 |
+
except:
|
37 |
+
|
38 |
+
|
39 |
+
gpt_response = """Sorry, I'm quite busy right now, but please try again later :)"""
|
40 |
+
|
41 |
+
print(f"""
|
42 |
+
{whisper_text}
|
43 |
+
ββββ
|
44 |
+
{gpt_response}
|
45 |
+
""")
|
46 |
+
|
47 |
+
return whisper_text, gpt_response
|
48 |
+
|
49 |
+
|
50 |
+
def translate(audio, task):
|
51 |
+
|
52 |
+
if task == "transcribe":
|
53 |
+
text_result = whisper(audio, None, "transcribe", fn_index=0)
|
54 |
+
else:
|
55 |
+
text_result = whisper(audio, None, "translate", fn_index=0)
|
56 |
+
|
57 |
+
return text_result
|
58 |
+
|
59 |
+
title = """
|
60 |
+
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
|
61 |
+
<div
|
62 |
+
style="
|
63 |
+
display: inline-flex;
|
64 |
+
align-items: center;
|
65 |
+
gap: 0.8rem;
|
66 |
+
font-size: 1.75rem;
|
67 |
+
margin-bottom: 10px;
|
68 |
+
"
|
69 |
+
>
|
70 |
+
<h1 style="font-weight: 600; margin-bottom: 7px;">
|
71 |
+
Whisper to chatGPT
|
72 |
+
</h1>
|
73 |
+
</div>
|
74 |
+
<p style="margin-bottom: 10px;font-size: 94%;font-weight: 100;line-height: 1.5em;">
|
75 |
+
Chat with GPT with your voice in your native language !
|
76 |
+
<!--<br />If you need a custom session key, see
|
77 |
+
<a href="https://youtu.be/TdNSj_qgdFk" target="_blank">Bhavesh Baht video for reference</a>
|
78 |
+
</p>-->
|
79 |
+
<!--<p style="font-size: 94%">
|
80 |
+
You can skip the queue by duplicating this space:
|
81 |
+
<span style="display: flex;align-items: center;justify-content: center;height: 30px;">
|
82 |
+
<a href="https://huggingface.co/fffiloni/whisper-to-chatGPT?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a>
|
83 |
+
</span>
|
84 |
+
</p>-->
|
85 |
+
</div>
|
86 |
+
"""
|
87 |
+
|
88 |
+
article = """
|
89 |
+
<p style="font-size: 0.8em;line-height: 1.2em;">Note: this demo is not able to sustain a conversation from earlier responses.
|
90 |
+
For more detailed results and dialogue, you should use the official ChatGPT interface.
|
91 |
+
<br />β
|
92 |
+
<br/>Also, be aware that audio records from iOS devices will not be decoded as expected by Gradio. For the best experience, record your voice from a computer instead of your smartphone ;)</p>
|
93 |
+
<div class="footer">
|
94 |
+
<p>Whisper &
|
95 |
+
<a href="https://chat.openai.com/chat" target="_blank">chatGPT</a>
|
96 |
+
by <a href="https://openai.com/" style="text-decoration: underline;" target="_blank">OpenAI</a> -
|
97 |
+
Gradio Demo by π€ <a href="https://twitter.com/fffiloni" target="_blank">Sylvain Filoni</a>
|
98 |
+
</p>
|
99 |
+
</div>
|
100 |
+
"""
|
101 |
+
|
102 |
+
css = '''
|
103 |
+
#col-container, #col-container-2 {max-width: 510px; margin-left: auto; margin-right: auto;}
|
104 |
+
a {text-decoration-line: underline; font-weight: 600;}
|
105 |
+
div#record_btn > .mt-6 {
|
106 |
+
margin-top: 0!important;
|
107 |
+
}
|
108 |
+
div#record_btn > .mt-6 button {
|
109 |
+
width: 100%;
|
110 |
+
height: 40px;
|
111 |
+
}
|
112 |
+
.footer {
|
113 |
+
margin-bottom: 45px;
|
114 |
+
margin-top: 10px;
|
115 |
+
text-align: center;
|
116 |
+
border-bottom: 1px solid #e5e5e5;
|
117 |
+
}
|
118 |
+
.footer>p {
|
119 |
+
font-size: .8rem;
|
120 |
+
display: inline-block;
|
121 |
+
padding: 0 10px;
|
122 |
+
transform: translateY(10px);
|
123 |
+
background: white;
|
124 |
+
}
|
125 |
+
.dark .footer {
|
126 |
+
border-color: #303030;
|
127 |
+
}
|
128 |
+
.dark .footer>p {
|
129 |
+
background: #0b0f19;
|
130 |
+
}
|
131 |
+
'''
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
+
with gr.Blocks(css=css) as demo:
|
136 |
+
|
137 |
+
with gr.Column(elem_id="col-container"):
|
138 |
+
|
139 |
+
gr.HTML(title)
|
140 |
+
|
141 |
+
with gr.Row():
|
142 |
+
record_input = gr.Audio(source="microphone",type="filepath", show_label=False,elem_id="record_btn")
|
143 |
+
task = gr.Radio(choices=["transcribe","translate"], value="transcribe", show_label=False)
|
144 |
+
|
145 |
+
with gr.Row():
|
146 |
+
#reset_conversation = gr.Checkbox(label="Reset conversation?", value=False)
|
147 |
+
send_btn = gr.Button("Send my request !")
|
148 |
+
#custom_token = gr.Textbox(label='If it fails, use your own session token', placeholder="your own session token", max_lines=3)
|
149 |
+
|
150 |
+
with gr.Column(elem_id="col-container-2"):
|
151 |
+
audio_translation = gr.Textbox(type="text",label="Whisper transcript")
|
152 |
+
gpt_response = gr.Textbox(type="text",label="chatGPT response")
|
153 |
+
|
154 |
+
gr.HTML(article)
|
155 |
+
|
156 |
+
send_btn.click(chat_hf, inputs=[record_input, task], outputs=[audio_translation, gpt_response])
|
157 |
+
|
158 |
+
demo.queue(max_size=32, concurrency_count=20).launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
pyChatGPT
|
2 |
+
requests
|
3 |
+
#git+https://github.com/fffiloni/pyChatGPT
|