MuhammadQASIM111 commited on
Commit
65fe33a
·
verified ·
1 Parent(s): 2ce19ed

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load the BioGPT model from HuggingFace or another medical GPT model
5
+ # BioGPT has been fine-tuned on medical data and should provide better responses
6
+ generator = pipeline("text-generation", model="microsoft/BioGPT")
7
+
8
+ # Streamlit app title
9
+ st.title("24/7Dr. Health Chatbot")
10
+
11
+ # Initialize session state for conversation history
12
+ if 'history' not in st.session_state:
13
+ st.session_state.history = []
14
+
15
+ # Function to generate chatbot responses using BioGPT
16
+ def generate_medical_response(user_input):
17
+ # Generate a response using BioGPT (or another medical model)
18
+ response = generator(user_input,
19
+ max_length=150,
20
+ num_return_sequences=1,
21
+ pad_token_id=50256,
22
+ truncation=True,
23
+ temperature=0.7,
24
+ top_k=50,
25
+ top_p=0.95)
26
+ return response[0]['generated_text']
27
+
28
+ # Input box for user symptoms
29
+ user_input = st.text_input("Describe your symptoms:")
30
+
31
+ if st.button("Ask"):
32
+ if user_input:
33
+ # Store the user's input in the conversation history
34
+ st.session_state.history.append(f"You: {user_input}")
35
+
36
+ # Generate the chatbot's response using the BioGPT model
37
+ bot_response = generate_medical_response(user_input)
38
+
39
+ # Store the chatbot's response in the conversation history
40
+ st.session_state.history.append(f"Bot: {bot_response}")
41
+
42
+ # Clear the input box
43
+ user_input = ""
44
+
45
+ # Display the conversation history
46
+ if st.session_state.history:
47
+ st.subheader("Conversation History")
48
+ for message in st.session_state.history:
49
+ st.write(message)