Upload 5 files
Browse files- Dockerfile +1 -1
- README.md +1 -1
- nlu.py +9 -6
- requirements.txt +1 -1
- translation.py +9 -6
Dockerfile
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
# (Docker deploy), Fly.io, Cloud Run, or any other platform that runs a
|
| 4 |
# standard Docker image. Nothing here is tied to one specific host.
|
| 5 |
# Configuration comes entirely from environment variables set by
|
| 6 |
-
# whichever platform runs it (PORT, DATABASE_URL,
|
| 7 |
# SECRET_KEY, ENVIRONMENT).
|
| 8 |
|
| 9 |
FROM python:3.11-slim
|
|
|
|
| 3 |
# (Docker deploy), Fly.io, Cloud Run, or any other platform that runs a
|
| 4 |
# standard Docker image. Nothing here is tied to one specific host.
|
| 5 |
# Configuration comes entirely from environment variables set by
|
| 6 |
+
# whichever platform runs it (PORT, DATABASE_URL, OPENAI_API_KEY,
|
| 7 |
# SECRET_KEY, ENVIRONMENT).
|
| 8 |
|
| 9 |
FROM python:3.11-slim
|
README.md
CHANGED
|
@@ -19,5 +19,5 @@ This Space runs the full application: speech-to-text, translation,
|
|
| 19 |
symptom summarization, and text-to-speech, in the patient's own
|
| 20 |
language.
|
| 21 |
|
| 22 |
-
Requires
|
| 23 |
secrets in this Space's settings.
|
|
|
|
| 19 |
symptom summarization, and text-to-speech, in the patient's own
|
| 20 |
language.
|
| 21 |
|
| 22 |
+
Requires OPENAI_API_KEY, SECRET_KEY, and DATABASE_URL to be set as
|
| 23 |
secrets in this Space's settings.
|
nlu.py
CHANGED
|
@@ -9,7 +9,7 @@ explicit that the system does not provide formal medical diagnosis, so
|
|
| 9 |
this module only summarizes what the patient is communicating, it never
|
| 10 |
suggests a diagnosis or treatment.
|
| 11 |
|
| 12 |
-
Uses the
|
| 13 |
|
| 14 |
MOCK_MODE: if set to "true" in the env file, this uses simple keyword
|
| 15 |
matching instead of a real API call, so the rest of the app can be tested
|
|
@@ -24,10 +24,10 @@ load_dotenv("env")
|
|
| 24 |
MOCK_MODE = os.environ.get("MOCK_MODE", "").lower() == "true"
|
| 25 |
|
| 26 |
if not MOCK_MODE:
|
| 27 |
-
from
|
| 28 |
-
_client =
|
| 29 |
|
| 30 |
-
MODEL = "
|
| 31 |
|
| 32 |
_MOCK_KEYWORDS = ["headache", "fever", "stomach", "cough", "dizzy", "pain", "vomit", "rash"]
|
| 33 |
|
|
@@ -53,8 +53,11 @@ def interpret_query(english_text):
|
|
| 53 |
f"Message: {english_text}"
|
| 54 |
)
|
| 55 |
|
| 56 |
-
response = _client.
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
|
|
|
| 9 |
this module only summarizes what the patient is communicating, it never
|
| 10 |
suggests a diagnosis or treatment.
|
| 11 |
|
| 12 |
+
Uses the OpenAI API, same as translation.py.
|
| 13 |
|
| 14 |
MOCK_MODE: if set to "true" in the env file, this uses simple keyword
|
| 15 |
matching instead of a real API call, so the rest of the app can be tested
|
|
|
|
| 24 |
MOCK_MODE = os.environ.get("MOCK_MODE", "").lower() == "true"
|
| 25 |
|
| 26 |
if not MOCK_MODE:
|
| 27 |
+
from openai import OpenAI
|
| 28 |
+
_client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
| 29 |
|
| 30 |
+
MODEL = "gpt-5.6-terra"
|
| 31 |
|
| 32 |
_MOCK_KEYWORDS = ["headache", "fever", "stomach", "cough", "dizzy", "pain", "vomit", "rash"]
|
| 33 |
|
|
|
|
| 53 |
f"Message: {english_text}"
|
| 54 |
)
|
| 55 |
|
| 56 |
+
response = _client.chat.completions.create(
|
| 57 |
+
model=MODEL,
|
| 58 |
+
messages=[{"role": "user", "content": prompt}],
|
| 59 |
+
)
|
| 60 |
+
return response.choices[0].message.content.strip()
|
| 61 |
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
flask==3.1.3
|
| 2 |
python-dotenv==1.2.2
|
| 3 |
-
|
| 4 |
openai-whisper==20250625
|
| 5 |
transformers==5.14.1
|
| 6 |
torch==2.5.0
|
|
|
|
| 1 |
flask==3.1.3
|
| 2 |
python-dotenv==1.2.2
|
| 3 |
+
openai==2.50.0
|
| 4 |
openai-whisper==20250625
|
| 5 |
transformers==5.14.1
|
| 6 |
torch==2.5.0
|
translation.py
CHANGED
|
@@ -3,7 +3,7 @@ Translation for TalkToDoc.
|
|
| 3 |
Translates patient input into English for the provider, and translates the
|
| 4 |
provider's reply back into the patient's selected language.
|
| 5 |
|
| 6 |
-
Uses the
|
| 7 |
|
| 8 |
MOCK_MODE: if set to "true" in the env file, this skips the real API call
|
| 9 |
entirely and returns the input text unchanged instead. This exists so
|
|
@@ -21,11 +21,11 @@ load_dotenv("env")
|
|
| 21 |
MOCK_MODE = os.environ.get("MOCK_MODE", "").lower() == "true"
|
| 22 |
|
| 23 |
if not MOCK_MODE:
|
| 24 |
-
from
|
| 25 |
-
_client =
|
| 26 |
|
| 27 |
SUPPORTED_LANGUAGES = ["english", "yoruba", "hausa", "igbo", "pidgin"]
|
| 28 |
-
MODEL = "
|
| 29 |
|
| 30 |
|
| 31 |
def translate(text, source_language, target_language):
|
|
@@ -46,8 +46,11 @@ def translate(text, source_language, target_language):
|
|
| 46 |
f"Text: {text}"
|
| 47 |
)
|
| 48 |
|
| 49 |
-
response = _client.
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
|
|
|
| 3 |
Translates patient input into English for the provider, and translates the
|
| 4 |
provider's reply back into the patient's selected language.
|
| 5 |
|
| 6 |
+
Uses the OpenAI API, via the official openai SDK.
|
| 7 |
|
| 8 |
MOCK_MODE: if set to "true" in the env file, this skips the real API call
|
| 9 |
entirely and returns the input text unchanged instead. This exists so
|
|
|
|
| 21 |
MOCK_MODE = os.environ.get("MOCK_MODE", "").lower() == "true"
|
| 22 |
|
| 23 |
if not MOCK_MODE:
|
| 24 |
+
from openai import OpenAI
|
| 25 |
+
_client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
| 26 |
|
| 27 |
SUPPORTED_LANGUAGES = ["english", "yoruba", "hausa", "igbo", "pidgin"]
|
| 28 |
+
MODEL = "gpt-5.6-terra"
|
| 29 |
|
| 30 |
|
| 31 |
def translate(text, source_language, target_language):
|
|
|
|
| 46 |
f"Text: {text}"
|
| 47 |
)
|
| 48 |
|
| 49 |
+
response = _client.chat.completions.create(
|
| 50 |
+
model=MODEL,
|
| 51 |
+
messages=[{"role": "user", "content": prompt}],
|
| 52 |
+
)
|
| 53 |
+
return response.choices[0].message.content.strip()
|
| 54 |
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|