Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +25 -36
- requirements.txt.txt +2 -1
app.py
CHANGED
|
@@ -1,43 +1,32 @@
|
|
| 1 |
-
|
| 2 |
-
from deep_translator import GoogleTranslator
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
def translate_to_en(text):
|
| 15 |
-
return GoogleTranslator(source='auto', target='en').translate(text)
|
| 16 |
-
|
| 17 |
-
def translate_to_th(text):
|
| 18 |
-
return GoogleTranslator(source='en', target='th').translate(text)
|
| 19 |
-
|
| 20 |
-
# Main Q&A function
|
| 21 |
-
def answer(user_input, lang_toggle):
|
| 22 |
-
if lang_toggle == "ไทย":
|
| 23 |
-
input_en = translate_to_en(user_input)
|
| 24 |
-
response = qa_pipeline(question=input_en, context=kratom_context)['answer']
|
| 25 |
-
return translate_to_th(response)
|
| 26 |
-
else:
|
| 27 |
-
|
| 28 |
-
response = qa_pipeline(question=user_input, context=kratom_context)['answer']
|
| 29 |
-
return response
|
| 30 |
-
|
| 31 |
-
# Gradio interface
|
| 32 |
iface = gr.Interface(
|
| 33 |
-
fn=
|
| 34 |
-
inputs=
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
outputs="text",
|
| 39 |
-
title="🧠 Kratom Clinical Tutor",
|
| 40 |
-
description="Ask Thai/English questions about Kratom's effects, risks, and pharmacology",
|
| 41 |
)
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# ✅ Define Kratom knowledge base
|
| 5 |
+
kratom_contexts = {
|
| 6 |
+
"urination": "Kratom may affect urination by interacting with the autonomic nervous system, leading to increased frequency or discomfort in some cases.",
|
| 7 |
+
"skin": "Long-term Kratom use has been associated with skin darkening and dryness, possibly linked to hormonal or liver-related effects.",
|
| 8 |
+
"behavior": "Depending on the dosage, Kratom can cause stimulant-like or sedative behaviors—including euphoria, drowsiness, agitation, and even dependency with prolonged use.",
|
| 9 |
+
"heart": "Kratom may influence heart rate and blood pressure. Some users report palpitations or arrhythmia, especially at high doses.",
|
| 10 |
+
"eyes": "Miosis (pupil constriction) and blurred vision have occasionally been observed with Kratom use due to its opioid-like activity.",
|
| 11 |
+
}
|
| 12 |
|
| 13 |
+
# ✅ Basic Q&A logic with keyword matching
|
| 14 |
+
def answer_question(user_input):
|
| 15 |
+
user_input = user_input.lower()
|
| 16 |
+
for keyword in kratom_contexts:
|
| 17 |
+
if keyword in user_input:
|
| 18 |
+
return kratom_contexts[keyword]
|
| 19 |
+
return "🧪 I couldn’t find matching context. Try asking about specific body systems like 'urination', 'skin', or 'behavior'."
|
| 20 |
|
| 21 |
+
# ✅ Build Gradio interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
iface = gr.Interface(
|
| 23 |
+
fn=answer_question,
|
| 24 |
+
inputs=gr.Textbox(label="Ask about Kratom effects (English only for now)"),
|
| 25 |
+
outputs=gr.Textbox(label="Medical Tutor Response"),
|
| 26 |
+
title="Kratom Context Tutor",
|
| 27 |
+
description="Keyword-driven answers about Kratom effects. Built for health education—expandable with Thai, visuals, or AI integration."
|
|
|
|
|
|
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
+
# ✅ Launch the app
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
iface.launch()
|
requirements.txt.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
transformers
|
| 2 |
deep-translator
|
| 3 |
-
gradio
|
|
|
|
|
|
| 1 |
transformers
|
| 2 |
deep-translator
|
| 3 |
+
gradio
|
| 4 |
+
torch
|