alibidaran commited on
Commit
e50ecf8
·
verified ·
1 Parent(s): c595232

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +80 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,82 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+ import streamlit.components.v1 as components
5
 
6
+
7
+ # Set Streamlit page config for a clinical look
8
+ st.set_page_config(
9
+ page_title="Symptom2Disease Clinical AI",
10
+ page_icon="🩺",
11
+ layout="centered"
12
+ )
13
+
14
+ # Clinical-themed header
15
+ st.title("🩺 Symptom2Disease Clinical AI")
16
+ st.markdown("""
17
+ Welcome to the **Symptom2Disease** clinical assistant.
18
+ Enter your symptoms below and our AI will suggest possible diseases.
19
+ """)
20
+
21
+ # Load model and tokenizer
22
+ @st.cache_resource
23
+ def load_model():
24
+ tokenizer = AutoTokenizer.from_pretrained("alibidaran/Symptom2disease")
25
+ model = AutoModelForSequenceClassification.from_pretrained("alibidaran/Symptom2disease")
26
+ return tokenizer, model
27
+
28
+ tokenizer, model = load_model()
29
+
30
+ label_2id = {
31
+ 'Psoriasis': 0, 'Varicose Veins': 1, 'Typhoid': 2, 'Chicken pox': 3, 'Impetigo': 4,
32
+ 'Dengue': 5, 'Fungal infection': 6, 'Common Cold': 7, 'Pneumonia': 8, 'Dimorphic Hemorrhoids': 9,
33
+ 'Arthritis': 10, 'Acne': 11, 'Bronchial Asthma': 12, 'Hypertension': 13, 'Migraine': 14,
34
+ 'Cervical spondylosis': 15, 'Jaundice': 16, 'Malaria': 17, 'urinary tract infection': 18,
35
+ 'allergy': 19, 'gastroesophageal reflux disease': 20, 'drug reaction': 21, 'peptic ulcer disease': 22,
36
+ 'diabetes': 23
37
+ }
38
+ id2label = {i: v for v, i in label_2id.items()}
39
+
40
+ def detect_symptom(symptoms):
41
+ inputs_id = tokenizer(symptoms, padding=True, truncation=True, return_tensors="pt")
42
+ output = model(inputs_id['input_ids'])
43
+ preds = torch.nn.functional.softmax(output.logits, -1).topk(5)
44
+ results = {id2label[preds.indices[0][i].item()]: float(preds.values[0][i].item()) for i in range(5)}
45
+ return results
46
+
47
+ # Example symptoms for quick testing
48
+ examples = [
49
+ "I can't stop sneezing and I feel really tired and crummy. My throat is really sore",
50
+ "I have been experiencing a severe headache that is accompanied by pain behind my eyes.",
51
+ "There are small red spots all over my body that I can't explain. It's worrying me.",
52
+ "I've been having a really hard time going to the bathroom lately. It's really painful"
53
+ ]
54
+
55
+ with st.expander("📝 Example symptom descriptions"):
56
+ for ex in examples:
57
+ st.code(ex)
58
+
59
+ # User input
60
+ symptoms = st.text_area(
61
+ "Describe your symptoms:",
62
+ placeholder="e.g. I have a persistent cough and mild fever for the last 3 days.",
63
+ height=100
64
+ )
65
+
66
+ if st.button("Analyze Symptoms", type="primary"):
67
+ if symptoms.strip():
68
+ with st.spinner("Analyzing symptoms..."):
69
+ results = detect_symptom(symptoms)
70
+ st.subheader("Top 5 Predicted Diseases")
71
+ for disease, prob in results.items():
72
+ st.markdown(f"**{disease}**")
73
+ st.progress(prob)
74
+ st.caption(f"Probability: {prob:.2%}")
75
+ else:
76
+ st.warning("Please enter your symptoms above.")
77
+
78
+ st.markdown("---")
79
+ st.info("**Disclaimer:** This tool is for informational purposes only and does not provide medical advice. Please consult a healthcare professional for diagnosis and treatment.")
80
+ components.iframe(
81
+ src="http://127.0.0.1:8080",
82
+ height=200)