Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import requests
|
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
# Set your FastAPI backend endpoint
|
| 7 |
-
BACKEND_URL = "https://
|
| 8 |
|
| 9 |
# Map of models
|
| 10 |
model_map = {
|
|
@@ -24,36 +24,47 @@ def transcribe(audio, language):
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
|
|
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
# Set your FastAPI backend endpoint
|
| 7 |
+
BACKEND_URL = "https://35d2-41-84-202-90.ngrok-free.app/submit-feedback"
|
| 8 |
|
| 9 |
# Map of models
|
| 10 |
model_map = {
|
|
|
|
| 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 |
try:
|
| 28 |
+
# Read binary content of audio file
|
| 29 |
+
with open(audio_file, "rb") as f:
|
| 30 |
+
audio_content = f.read()
|
| 31 |
+
|
| 32 |
+
# Prepare metadata as form fields
|
| 33 |
+
metadata = {
|
| 34 |
+
"transcription": transcription,
|
| 35 |
+
"age_group": age_group,
|
| 36 |
+
"gender": gender,
|
| 37 |
+
"evaluated_language": evaluated_language,
|
| 38 |
+
"speak_level": speak_level,
|
| 39 |
+
"write_level": write_level,
|
| 40 |
+
"native": native,
|
| 41 |
+
"native_language": native_language,
|
| 42 |
+
"environment": env,
|
| 43 |
+
"device": device,
|
| 44 |
+
"domain": domain,
|
| 45 |
+
"accuracy": accuracy,
|
| 46 |
+
"orthography": orthography,
|
| 47 |
+
"meaning": meaning,
|
| 48 |
+
"errors": ",".join(errors) if errors else "",
|
| 49 |
+
"performance": performance,
|
| 50 |
+
"improvement": improvement,
|
| 51 |
+
"usability": usability,
|
| 52 |
+
"technical_issues": technical_issues,
|
| 53 |
+
"final_comments": final_comments,
|
| 54 |
+
"email": email
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
files = {
|
| 58 |
+
"audio_file": ("audio.wav", audio_content, "audio/wav")
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
response = requests.post(BACKEND_URL, data=metadata, files=files, timeout=20)
|
| 62 |
+
|
| 63 |
if response.status_code == 201:
|
| 64 |
return "✅ Feedback submitted successfully. Thank you!"
|
| 65 |
else:
|
| 66 |
return f"⚠️ Submission failed: {response.status_code} — {response.text}"
|
| 67 |
+
|
| 68 |
except Exception as e:
|
| 69 |
return f"❌ Could not connect to the backend: {str(e)}"
|
| 70 |
|