trapezius60 commited on
Commit
86bfcb6
·
verified ·
1 Parent(s): 27bf6f2

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +25 -36
  2. requirements.txt.txt +2 -1
app.py CHANGED
@@ -1,43 +1,32 @@
1
- from transformers import pipeline
2
- from deep_translator import GoogleTranslator
3
  import gradio as gr
4
 
5
- # Load BioGPT model pipeline
6
- qa_pipeline = pipeline("question-answering", model="microsoft/BioGPT")
 
 
 
 
 
 
7
 
8
- # Your curated context (replace this with actual medical Kratom knowledge)
9
- kratom_context = """
10
- Kratom (Mitragyna speciosa) is a tropical tree native to Southeast Asia. Its leaves contain alkaloids like mitragynine and 7-hydroxymitragynine, which act on opioid receptors. Common effects include stimulation at low doses and sedation at higher doses. Side effects may include nausea, constipation, dizziness, and dependence. Kratom has traditional uses for fatigue relief and pain management, but clinical safety remains under study.
11
- """
 
 
 
12
 
13
- # Translation helpers
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=answer,
34
- inputs=[
35
- gr.Textbox(label="Ask a Kratom-related question"),
36
- gr.Radio(["English", "ไทย"], label="Language")
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
- iface.launch()
 
 
 
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