Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -41,11 +41,13 @@ def translate(text, src_lang, tgt_lang="eng_Latn"):
|
|
41 |
)
|
42 |
return translation_pipeline(text)[0]["translation_text"]
|
43 |
|
44 |
-
def process_feedback(audio_np, language):
|
|
|
|
|
|
|
45 |
if audio_np is None:
|
46 |
return "No audio provided", None
|
47 |
|
48 |
-
# Transcribe
|
49 |
model_name, src_lang = lang_map[language]
|
50 |
transcriber = pipeline("automatic-speech-recognition", model=model_name)
|
51 |
transcription = transcriber(audio_np)["text"]
|
@@ -53,10 +55,8 @@ def process_feedback(audio_np, language):
|
|
53 |
if language != "English":
|
54 |
transcription = translate(transcription, src_lang=src_lang)
|
55 |
|
56 |
-
# Summarize
|
57 |
summary = summarizer(transcription, max_length=60, min_length=10, do_sample=False)[0]["summary_text"]
|
58 |
|
59 |
-
# Save record
|
60 |
feedback_records.append({
|
61 |
"timestamp": datetime.utcnow().isoformat(),
|
62 |
"language": language,
|
@@ -64,7 +64,6 @@ def process_feedback(audio_np, language):
|
|
64 |
"summary": summary
|
65 |
})
|
66 |
|
67 |
-
# Word cloud
|
68 |
feedback_words.extend(summary.lower().split())
|
69 |
wordcloud_img = generate_wordcloud(feedback_words)
|
70 |
|
@@ -106,6 +105,18 @@ with demo:
|
|
106 |
audio_input = gr.Audio(type="numpy", label="π€ Upload your feedback audio")
|
107 |
lang_dropdown = gr.Dropdown(label="π Language", choices=["English", "Hindi", "Telugu", "Tamil", "Kannada"], value="English")
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
with gr.Row():
|
110 |
submit_btn = gr.Button("β
Process Feedback")
|
111 |
|
@@ -117,7 +128,7 @@ with demo:
|
|
117 |
export_btn = gr.Button("π Export Feedback to CSV")
|
118 |
csv_file_output = gr.File(label="π Download CSV")
|
119 |
|
120 |
-
submit_btn.click(process_feedback, inputs=[audio_input, lang_dropdown], outputs=[summary_out, wordcloud_out])
|
121 |
export_btn.click(export_to_csv, inputs=[], outputs=csv_file_output)
|
122 |
|
123 |
demo.launch()
|
|
|
41 |
)
|
42 |
return translation_pipeline(text)[0]["translation_text"]
|
43 |
|
44 |
+
def process_feedback(audio_np, language, sample_file):
|
45 |
+
if audio_np is None and sample_file:
|
46 |
+
audio_np, _ = sf.read(sample_file)
|
47 |
+
|
48 |
if audio_np is None:
|
49 |
return "No audio provided", None
|
50 |
|
|
|
51 |
model_name, src_lang = lang_map[language]
|
52 |
transcriber = pipeline("automatic-speech-recognition", model=model_name)
|
53 |
transcription = transcriber(audio_np)["text"]
|
|
|
55 |
if language != "English":
|
56 |
transcription = translate(transcription, src_lang=src_lang)
|
57 |
|
|
|
58 |
summary = summarizer(transcription, max_length=60, min_length=10, do_sample=False)[0]["summary_text"]
|
59 |
|
|
|
60 |
feedback_records.append({
|
61 |
"timestamp": datetime.utcnow().isoformat(),
|
62 |
"language": language,
|
|
|
64 |
"summary": summary
|
65 |
})
|
66 |
|
|
|
67 |
feedback_words.extend(summary.lower().split())
|
68 |
wordcloud_img = generate_wordcloud(feedback_words)
|
69 |
|
|
|
105 |
audio_input = gr.Audio(type="numpy", label="π€ Upload your feedback audio")
|
106 |
lang_dropdown = gr.Dropdown(label="π Language", choices=["English", "Hindi", "Telugu", "Tamil", "Kannada"], value="English")
|
107 |
|
108 |
+
with gr.Row():
|
109 |
+
sample_selector = gr.Dropdown(
|
110 |
+
label="π§ Try with sample audio (optional)",
|
111 |
+
choices=[
|
112 |
+
"files/telugu.mp3",
|
113 |
+
"files/hindi.mp3",
|
114 |
+
"files/tamil.mp3",
|
115 |
+
"files/english.mp3"
|
116 |
+
],
|
117 |
+
value=None
|
118 |
+
)
|
119 |
+
|
120 |
with gr.Row():
|
121 |
submit_btn = gr.Button("β
Process Feedback")
|
122 |
|
|
|
128 |
export_btn = gr.Button("π Export Feedback to CSV")
|
129 |
csv_file_output = gr.File(label="π Download CSV")
|
130 |
|
131 |
+
submit_btn.click(process_feedback, inputs=[audio_input, lang_dropdown, sample_selector], outputs=[summary_out, wordcloud_out])
|
132 |
export_btn.click(export_to_csv, inputs=[], outputs=csv_file_output)
|
133 |
|
134 |
demo.launch()
|