goctests0 commited on
Commit
cc4d8d8
·
verified ·
1 Parent(s): abb1592

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -25,7 +25,7 @@ import translation
25
  import nlu
26
  import tts
27
 
28
- load_dotenv()
29
 
30
  AUDIO_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static", "audio")
31
 
@@ -77,6 +77,33 @@ def provider_page():
77
  return render_template("provider.html")
78
 
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  @app.route("/patient-input", methods=["POST"])
81
  def patient_input():
82
  language = request.form.get("language")
 
25
  import nlu
26
  import tts
27
 
28
+ load_dotenv("env")
29
 
30
  AUDIO_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static", "audio")
31
 
 
77
  return render_template("provider.html")
78
 
79
 
80
+ @app.route("/transcribe", methods=["POST"])
81
+ def transcribe_only():
82
+ """
83
+ Transcribes an audio recording without saving anything or translating
84
+ it. Used by the transcript review step, so the patient can see and
85
+ edit what was heard before it becomes the message actually sent to
86
+ the provider. Nothing here touches the database.
87
+ """
88
+ language = request.form.get("language")
89
+ if not language or language.lower() not in translation.SUPPORTED_LANGUAGES:
90
+ return jsonify({"error": f"language must be one of {translation.SUPPORTED_LANGUAGES}"}), 400
91
+ language = language.lower()
92
+
93
+ audio_file = request.files.get("audio")
94
+ if not audio_file:
95
+ return jsonify({"error": "provide an audio file"}), 400
96
+
97
+ temp_path = os.path.join(AUDIO_DIR, f"transcribe_{uuid.uuid4().hex}.wav")
98
+ audio_file.save(temp_path)
99
+ try:
100
+ patient_text = stt.transcribe_audio(temp_path, language)
101
+ finally:
102
+ os.remove(temp_path)
103
+
104
+ return jsonify({"patient_text": patient_text})
105
+
106
+
107
  @app.route("/patient-input", methods=["POST"])
108
  def patient_input():
109
  language = request.form.get("language")