Spaces:
Runtime error
Runtime error
Duplicate from fffiloni/whisper-to-chatGPT
Browse filesCo-authored-by: Sylvain Filoni <[email protected]>
- .gitattributes +34 -0
- README.md +14 -0
- app.py +142 -0
- requirements.txt +2 -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.12.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,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pyChatGPT import ChatGPT
|
2 |
+
import os
|
3 |
+
session_token = os.environ.get('SessionToken')
|
4 |
+
|
5 |
+
import whisper
|
6 |
+
whisper_model = whisper.load_model("small")
|
7 |
+
|
8 |
+
|
9 |
+
def chat_hf(audio, custom_token):
|
10 |
+
try:
|
11 |
+
whisper_text = translate(audio)
|
12 |
+
api = ChatGPT(session_token)
|
13 |
+
resp = api.send_message(whisper_text)
|
14 |
+
|
15 |
+
|
16 |
+
api.refresh_auth() # refresh the authorization token
|
17 |
+
api.reset_conversation() # reset the conversation
|
18 |
+
gpt_response = resp['message']
|
19 |
+
|
20 |
+
except:
|
21 |
+
whisper_text = translate(audio)
|
22 |
+
api = ChatGPT(custom_token)
|
23 |
+
resp = api.send_message(whisper_text)
|
24 |
+
|
25 |
+
|
26 |
+
api.refresh_auth() # refresh the authorization token
|
27 |
+
api.reset_conversation() # reset the conversation
|
28 |
+
gpt_response = resp['message']
|
29 |
+
|
30 |
+
return whisper_text, gpt_response
|
31 |
+
|
32 |
+
|
33 |
+
def translate(audio):
|
34 |
+
print("""
|
35 |
+
β
|
36 |
+
Sending audio to Whisper ...
|
37 |
+
β
|
38 |
+
""")
|
39 |
+
|
40 |
+
audio = whisper.load_audio(audio)
|
41 |
+
audio = whisper.pad_or_trim(audio)
|
42 |
+
|
43 |
+
mel = whisper.log_mel_spectrogram(audio).to(whisper_model.device)
|
44 |
+
|
45 |
+
_, probs = whisper_model.detect_language(mel)
|
46 |
+
|
47 |
+
transcript_options = whisper.DecodingOptions(task="transcribe", fp16 = False)
|
48 |
+
#translate_options = whisper.DecodingOptions(task="translate", fp16 = False)
|
49 |
+
|
50 |
+
transcription = whisper.decode(whisper_model, mel, transcript_options)
|
51 |
+
#translation = whisper.decode(whisper_model, mel, translate_options)
|
52 |
+
|
53 |
+
print("language spoken: " + transcription.language)
|
54 |
+
print("transcript: " + transcription.text)
|
55 |
+
print("βββββββββββββββββββββββββββββββββββββββββββ")
|
56 |
+
#print("translated: " + translation.text)
|
57 |
+
|
58 |
+
return transcription.text
|
59 |
+
|
60 |
+
title = """
|
61 |
+
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
|
62 |
+
<div
|
63 |
+
style="
|
64 |
+
display: inline-flex;
|
65 |
+
align-items: center;
|
66 |
+
gap: 0.8rem;
|
67 |
+
font-size: 1.75rem;
|
68 |
+
margin-bottom: 10px;
|
69 |
+
"
|
70 |
+
>
|
71 |
+
<h1 style="font-weight: 600; margin-bottom: 7px;">
|
72 |
+
Whisper to chatGPT
|
73 |
+
</h1>
|
74 |
+
</div>
|
75 |
+
<p style="margin-bottom: 10px;font-size: 94%;font-weight: 100;line-height: 1.5em;">
|
76 |
+
Chat with GPT with your voice in your native language !
|
77 |
+
<br />If it fails enter custom session key see video for reference refer
|
78 |
+
<a href="https://youtu.be/TdNSj_qgdFk" target="_blank">Bhavesh Baht video</a>
|
79 |
+
</p>
|
80 |
+
<p style="font-size: 94%">
|
81 |
+
You can skip the queue by duplicating this space:
|
82 |
+
<span style="display: flex;align-items: center;justify-content: center;height: 30px;">
|
83 |
+
<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>
|
84 |
+
</span>
|
85 |
+
</p>
|
86 |
+
</div>
|
87 |
+
"""
|
88 |
+
|
89 |
+
article = """
|
90 |
+
<div class="footer">
|
91 |
+
<p><a href="https://chat.openai.com/chat" target="_blank">chatGPT</a>
|
92 |
+
by <a href="https://openai.com/" style="text-decoration: underline;" target="_blank">OpenAI</a> -
|
93 |
+
Gradio Demo by π€ <a href="https://twitter.com/fffiloni" target="_blank">Sylvain Filoni</a>
|
94 |
+
</p>
|
95 |
+
</div>
|
96 |
+
"""
|
97 |
+
|
98 |
+
css = '''
|
99 |
+
#col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
|
100 |
+
a {text-decoration-line: underline; font-weight: 600;}
|
101 |
+
.footer {
|
102 |
+
margin-bottom: 45px;
|
103 |
+
margin-top: 35px;
|
104 |
+
text-align: center;
|
105 |
+
border-bottom: 1px solid #e5e5e5;
|
106 |
+
}
|
107 |
+
.footer>p {
|
108 |
+
font-size: .8rem;
|
109 |
+
display: inline-block;
|
110 |
+
padding: 0 10px;
|
111 |
+
transform: translateY(10px);
|
112 |
+
background: white;
|
113 |
+
}
|
114 |
+
.dark .footer {
|
115 |
+
border-color: #303030;
|
116 |
+
}
|
117 |
+
.dark .footer>p {
|
118 |
+
background: #0b0f19;
|
119 |
+
}
|
120 |
+
'''
|
121 |
+
|
122 |
+
import gradio as gr
|
123 |
+
|
124 |
+
with gr.Blocks(css=css) as demo:
|
125 |
+
|
126 |
+
with gr.Column(elem_id="col-container"):
|
127 |
+
|
128 |
+
gr.HTML(title)
|
129 |
+
|
130 |
+
with gr.Row():
|
131 |
+
record_input = gr.Audio(source="microphone",type="filepath", show_label=False)
|
132 |
+
send_btn = gr.Button("Send my message !")
|
133 |
+
custom_token = gr.Textbox(label='If it fails, use your own session token', placeholder="your own session token")
|
134 |
+
with gr.Column():
|
135 |
+
audio_translation = gr.Textbox(type="text",label="Whisper translation")
|
136 |
+
gpt_response = gr.Textbox(type="text",label="chatGPT response")
|
137 |
+
|
138 |
+
gr.HTML(article)
|
139 |
+
|
140 |
+
send_btn.click(chat_hf, inputs=[record_input, custom_token], outputs=[audio_translation, gpt_response])
|
141 |
+
|
142 |
+
demo.queue(max_size=32, concurrency_count=20).launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
pyChatGPT
|
2 |
+
git+https://github.com/openai/whisper.git
|