Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +42 -0
- model/SmallDisMedLM.pt +3 -0
- requirements.txt +7 -0
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import torch
|
3 |
+
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
4 |
+
|
5 |
+
|
6 |
+
# Load model and tokenizer
|
7 |
+
model_path = "model/SmallDisMedLM.pt"
|
8 |
+
model = torch.load(model_path, map_location='cpu')
|
9 |
+
tokenizer = GPT2Tokenizer.from_pretrained('distilgpt2')
|
10 |
+
|
11 |
+
# Define UI elements with clear labels and spacing
|
12 |
+
st.title("Medical Chatbot 🩺")
|
13 |
+
|
14 |
+
st.header("Ask a question about your health:")
|
15 |
+
user_input = st.text_input("", placeholder="Type your query here...")
|
16 |
+
|
17 |
+
if st.button("Get Symptoms for a disease"):
|
18 |
+
with st.spinner("Generating response..."):
|
19 |
+
input_ids = tokenizer.encode(user_input, return_tensors='pt')
|
20 |
+
output = model.generate(
|
21 |
+
input_ids,
|
22 |
+
max_length=100,
|
23 |
+
num_return_sequences=1,
|
24 |
+
do_sample=True,
|
25 |
+
top_k=8,
|
26 |
+
top_p=0.95,
|
27 |
+
temperature=0.5,
|
28 |
+
repetition_penalty=1.2
|
29 |
+
)
|
30 |
+
decoded_output = tokenizer.decode(output[0], skip_special_tokens=True)
|
31 |
+
|
32 |
+
st.success("Chatbot Response:")
|
33 |
+
st.write(decoded_output)
|
34 |
+
|
35 |
+
st.markdown("---")
|
36 |
+
st.info("Disclaimer: This chatbot is not a substitute for professional medical advice. Always consult with a healthcare provider for diagnosis and treatment.")
|
37 |
+
|
38 |
+
st.sidebar.header("About")
|
39 |
+
st.sidebar.write("This chatbot is powered by a GPT-2 language model trained on medical text data. It aims to provide general information and advice, but it should not be relied upon for diagnosis or treatment.")
|
40 |
+
|
41 |
+
st.sidebar.header("Feedback")
|
42 |
+
st.sidebar.text_area("Please share any feedback or suggestions:")
|
model/SmallDisMedLM.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:61c4d5c83e519c284a27ab2dd397691e8021e33db4be20011de9f6d37a201d7e
|
3 |
+
size 333994102
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|
3 |
+
sentencepiece
|
4 |
+
pandas
|
5 |
+
tqdm
|
6 |
+
datasets
|
7 |
+
streamlit
|