File size: 2,508 Bytes
2d81770
 
 
 
 
 
 
 
 
 
 
 
e06b22f
 
3fdc359
e06b22f
 
2d81770
e06b22f
 
 
2d81770
e06b22f
 
 
 
 
 
 
 
 
 
 
256d4fe
e06b22f
f0144dd
e06b22f
 
 
1226db7
e06b22f
 
2ccd913
256d4fe
e06b22f
 
5b3c8c9
2d81770
 
 
 
e06b22f
2d81770
 
 
 
 
 
 
 
 
 
 
e06b22f
2d81770
 
 
e06b22f
 
2d81770
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# app.py
import streamlit as st
from groq import Groq
import os
from langdetect import detect

# Initialize Groq client
try:
    client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
except Exception as e:
    st.error(f"Groq initialization failed: {str(e)}")

# Main function to generate bilingual advice
def get_bilingual_advice(user_input):
    try:
        # Detect input language
        input_lang = detect(user_input)
        
        # Step 1: Generate English medical report
        medical_prompt = f"""As a homeopathic expert, analyze these symptoms: {user_input}
        Provide detailed recommendations in this format:

        **English Recommendation:**
        1. Medicine (Potency): Explanation
        - Dosage: ...
        - Key Symptoms: ...
        - Source: ...

        **Translated Recommendation ({input_lang}):**
        1. Same medicine name in English with translated explanation
        - Translated dosage instructions
        - Translated symptoms
        - Same source links
        
        Keep medicine names in English for both sections."""
        
        # Use larger 400B model for better multilingual support
        response = client.chat.completions.create(
            messages=[{"role": "user", "content": medical_prompt}],
            model="deepseek-r1-distill-llama-70b",  # Bigger model for better translations
            temperature=0.3,
            max_tokens=1000
        )
        
        return response.choices[0].message.content

    except Exception as e:
        return f"Error: {str(e)}"

# Streamlit UI Setup
st.set_page_config(page_title="Homeo Advisor", page_icon="🌿")
st.title("🌿 Multilingual Homeopathic Advisor")

# Initialize chat history
if "messages" not in st.session_state:
    st.session_state.messages = [{"role": "assistant", "content": "Describe your symptoms in any language"}]

# Display chat messages
for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])

# User input handling
if prompt := st.chat_input("Type your symptoms..."):
    st.session_state.messages.append({"role": "user", "content": prompt})
    
    with st.chat_message("assistant"):
        with st.spinner("Analyzing symptoms..."):
            response = get_bilingual_advice(prompt)
            st.markdown(response)
    st.session_state.messages.append({"role": "assistant", "content": response})

# Disclaimer
st.caption("⚠️ This is not medical advice. Consult a professional.")