KettaP commited on
Commit
9683cd0
·
verified ·
1 Parent(s): b632cd1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +108 -0
app.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import requests
4
+ from transformers import pipeline
5
+
6
+ # Set your FastAPI backend endpoint
7
+ BACKEND_URL = "https://09fc-41-84-202-90.ngrok-free.app/submit-feedback"
8
+
9
+ # Map of models
10
+ model_map = {
11
+ "english": "jonatasgrosman/wav2vec2-large-xlsr-53-english"
12
+ }
13
+
14
+ # Create storage directory
15
+ os.makedirs("responses", exist_ok=True)
16
+
17
+ # Transcription function
18
+ def transcribe(audio, language):
19
+ asr = pipeline("automatic-speech-recognition", model=model_map[language], device=0)
20
+ text = asr(audio)["text"]
21
+ return text, audio
22
+
23
+ # Save feedback by sending it to FastAPI backend
24
+ def save_feedback(audio_file, transcription, age_group, gender, evaluated_language, speak_level, write_level,
25
+ native, native_language, env, device, domain, accuracy, orthography, meaning, errors,
26
+ performance, improvement, usability, technical_issues, final_comments, email):
27
+ data = {
28
+ "transcription": transcription,
29
+ "age_group": age_group,
30
+ "gender": gender,
31
+ "evaluated_language": evaluated_language,
32
+ "speak_level": speak_level,
33
+ "write_level": write_level,
34
+ "native": native,
35
+ "native_language": native_language,
36
+ "environment": env,
37
+ "device": device,
38
+ "domain": domain,
39
+ "accuracy": accuracy,
40
+ "orthography": orthography,
41
+ "meaning": meaning,
42
+ "errors": errors,
43
+ "performance": performance,
44
+ "improvement": improvement,
45
+ "usability": usability,
46
+ "technical_issues": technical_issues,
47
+ "final_comments": final_comments,
48
+ "email": email
49
+ }
50
+
51
+ try:
52
+ response = requests.post(BACKEND_URL, json=data, timeout=10)
53
+ if response.status_code == 201:
54
+ return "✅ Feedback submitted successfully. Thank you!"
55
+ else:
56
+ return f"⚠️ Submission failed: {response.status_code} — {response.text}"
57
+ except Exception as e:
58
+ return f"❌ Could not connect to the backend: {str(e)}"
59
+
60
+
61
+ # Gradio UI
62
+ with gr.Blocks() as demo:
63
+ gr.Markdown("## African ASR + Feedback")
64
+
65
+ with gr.Row():
66
+ audio_input = gr.Audio(sources=["upload", "microphone"], type="filepath", label="Upload or record audio")
67
+ lang = gr.Dropdown(list(model_map.keys()), label="Select Language")
68
+
69
+ transcribed_text = gr.Textbox(label="Transcribed Text")
70
+ submit_btn = gr.Button("Transcribe")
71
+ submit_btn.click(fn=transcribe, inputs=[audio_input, lang], outputs=[transcribed_text, audio_input])
72
+
73
+ gr.Markdown("---\n## Feedback Form")
74
+
75
+ age_group = gr.Dropdown(["18 to 30", "31 to 50", "50+", "Prefer not to say"], label="Age Group")
76
+ gender = gr.Dropdown(["Male", "Female", "Prefer not to say", "Other"], label="Gender")
77
+ evaluated_language = gr.Dropdown(list(model_map.keys()), label="Which language did you evaluate for?")
78
+ speak_level = gr.Slider(1, 10, label="How well do you speak this language?")
79
+ write_level = gr.Slider(1, 10, label="How well do you write the language?")
80
+ native = gr.Radio(["Yes", "No"], label="Are you a native speaker of this language?")
81
+ native_language = gr.Textbox(label="If not, what is your native language?")
82
+ env = gr.Dropdown(["Studio/Professional Recording", "Quiet Room", "Noisy Background", "Multiple Environments", "Unsure", "Other"], label="Recording environment")
83
+ device = gr.Dropdown(["Mobile Phone/Tablet", "Tablet", "Laptop/Computer Microphone", "Dedicated Microphone", "Unsure", "Other"], label="Recording device")
84
+ domain = gr.Textbox(label="Was the speech related to a specific domain or topic? (Optional)")
85
+ accuracy = gr.Slider(1, 10, label="How accurate was the model’s transcription?")
86
+ orthography = gr.Dropdown(["Yes, mostly correct", "No, major issues", "Partially", "Not Applicable"], label="Did the transcription use standard orthography?")
87
+ meaning = gr.Slider(1, 10, label="Did the transcription preserve the original meaning?")
88
+ errors = gr.CheckboxGroup([
89
+ "Substitutions", "Omissions", "Insertions", "Pronunciation-related", "Diacritic Errors",
90
+ "Code-switching Errors", "Named Entity Errors", "Punctuation Errors", "No significant errors"
91
+ ], label="Which errors were prominent?")
92
+ performance = gr.Textbox(label="What did the model do well? What did it struggle with?")
93
+ improvement = gr.Textbox(label="How could this ASR model be improved?")
94
+ usability = gr.Slider(1, 5, label="How easy was it to use the tool?")
95
+ technical_issues = gr.Textbox(label="Did you encounter any technical issues?")
96
+ final_comments = gr.Textbox(label="Any other comments or suggestions?")
97
+ email = gr.Textbox(label="Email (optional)")
98
+
99
+ save_btn = gr.Button("Submit Feedback")
100
+ output_msg = gr.Textbox(interactive=False)
101
+ save_btn.click(fn=save_feedback,
102
+ inputs=[audio_input, transcribed_text, age_group, gender, evaluated_language, speak_level, write_level,
103
+ native, native_language, env, device, domain, accuracy, orthography, meaning, errors,
104
+ performance, improvement, usability, technical_issues, final_comments, email],
105
+ outputs=[output_msg])
106
+
107
+ # Launch the interface
108
+ demo.launch()