aminahmed78 commited on
Commit
832a096
·
verified ·
1 Parent(s): 2bfa4a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
2
  import os
3
  from groq import Groq
4
  from langdetect import detect, DetectorFactory
5
- import json
6
 
7
  # Ensure consistent language detection
8
  DetectorFactory.seed = 0
@@ -22,25 +22,28 @@ Your response must include:
22
  - Best possible remedy
23
  - Proper dosage and administration
24
  - Scientific or historical sources for reference
25
- - Store/availability of the medicine
26
  Ensure accuracy in medical details and maintain professionalism."""
27
 
 
 
 
28
  def detect_language(text):
29
- """Detect the language of the input text."""
30
  try:
31
- lang = detect(text)
32
- return lang
 
33
  except:
34
  return "en" # Default to English if detection fails
35
 
36
- def get_homeopathic_advice(symptoms, lang="en"):
37
  """Search the web for remedies and generate a professional homeopathic response."""
38
  try:
39
  response = groq_client.chat.completions.create(
40
  model="llama3-70b-8192",
41
  messages=[
42
  {"role": "system", "content": CHATBOT_ROLE},
43
- {"role": "user", "content": f"Find the best homeopathic remedy for: {symptoms}. Provide remedy details, usage, dose, sources, and availability."}
44
  ],
45
  temperature=0.3
46
  )
@@ -85,7 +88,7 @@ if prompt := st.chat_input("Describe your symptoms..."):
85
  detected_lang = detect_language(prompt)
86
 
87
  # Get homeopathic remedy
88
- homeo_advice = get_homeopathic_advice(prompt, detected_lang)
89
 
90
  # Translate advice if needed
91
  if detected_lang != "en":
 
2
  import os
3
  from groq import Groq
4
  from langdetect import detect, DetectorFactory
5
+ import re
6
 
7
  # Ensure consistent language detection
8
  DetectorFactory.seed = 0
 
22
  - Best possible remedy
23
  - Proper dosage and administration
24
  - Scientific or historical sources for reference
 
25
  Ensure accuracy in medical details and maintain professionalism."""
26
 
27
+ # Improve language detection, especially for Roman Urdu
28
+ ROMAN_URDU_PATTERN = re.compile(r'\b(mujhe|kamar|dard|hai|aap|kyun|kaisi|bohot|zyada|masla|kar|raha|rahi|hun|ho|hai)\b', re.IGNORECASE)
29
+
30
  def detect_language(text):
31
+ """Detect the language of the input text, with special handling for Roman Urdu."""
32
  try:
33
+ if ROMAN_URDU_PATTERN.search(text):
34
+ return "ur" # Detect Roman Urdu correctly
35
+ return detect(text)
36
  except:
37
  return "en" # Default to English if detection fails
38
 
39
+ def get_homeopathic_advice(symptoms):
40
  """Search the web for remedies and generate a professional homeopathic response."""
41
  try:
42
  response = groq_client.chat.completions.create(
43
  model="llama3-70b-8192",
44
  messages=[
45
  {"role": "system", "content": CHATBOT_ROLE},
46
+ {"role": "user", "content": f"Find the best homeopathic remedy for: {symptoms}. Provide remedy details, usage, dose, and sources."}
47
  ],
48
  temperature=0.3
49
  )
 
88
  detected_lang = detect_language(prompt)
89
 
90
  # Get homeopathic remedy
91
+ homeo_advice = get_homeopathic_advice(prompt)
92
 
93
  # Translate advice if needed
94
  if detected_lang != "en":