Tejha commited on
Commit
81b5c65
·
verified ·
1 Parent(s): 86e3300

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -18
app.py CHANGED
@@ -1,21 +1,13 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
  import nltk
4
- from nltk.corpus import stopwords
5
- from nltk.tokenize import word_tokenize
6
 
7
- # Download necessary NLTK data
8
  nltk.download('punkt')
9
  nltk.download('stopwords')
10
 
11
-
12
- # Load a pre-trained Hugging Face model
13
  chatbot = pipeline("text-generation", model="distilgpt2")
14
 
15
-
16
- # Define healthcare-specific response logic (or use a model to generate responses)
17
  def healthcare_chatbot(user_input):
18
- # Simple rule-based keywords to respond
19
  if "symptom" in user_input:
20
  return "It seems like you're experiencing symptoms. Please consult a doctor for accurate advice."
21
  elif "appointment" in user_input:
@@ -23,22 +15,12 @@ def healthcare_chatbot(user_input):
23
  elif "medication" in user_input:
24
  return "It's important to take your prescribed medications regularly. If you have concerns, consult your doctor."
25
  else:
26
- # For other inputs, use the Hugging Face model to generate a response
27
  response = chatbot(user_input, max_length=300, num_return_sequences=1)
28
- # Specifies the maximum length of the generated text response, including the input and the generated tokens.
29
- # If set to 3, the model generates three different possible responses based on the input.
30
  return response[0]['generated_text']
31
 
32
-
33
- # Streamlit web app interface
34
  def main():
35
- # Set up the web app title and input area
36
  st.title("Healthcare Assistant Chatbot")
37
-
38
- # Display a simple text input for user queries
39
  user_input = st.text_input("How can I assist you today?", "")
40
-
41
- # Display chatbot response
42
  if st.button("Submit"):
43
  if user_input:
44
  st.write("User: ", user_input)
 
1
  import streamlit as st
2
  from transformers import pipeline
3
  import nltk
 
 
4
 
 
5
  nltk.download('punkt')
6
  nltk.download('stopwords')
7
 
 
 
8
  chatbot = pipeline("text-generation", model="distilgpt2")
9
 
 
 
10
  def healthcare_chatbot(user_input):
 
11
  if "symptom" in user_input:
12
  return "It seems like you're experiencing symptoms. Please consult a doctor for accurate advice."
13
  elif "appointment" in user_input:
 
15
  elif "medication" in user_input:
16
  return "It's important to take your prescribed medications regularly. If you have concerns, consult your doctor."
17
  else:
 
18
  response = chatbot(user_input, max_length=300, num_return_sequences=1)
 
 
19
  return response[0]['generated_text']
20
 
 
 
21
  def main():
 
22
  st.title("Healthcare Assistant Chatbot")
 
 
23
  user_input = st.text_input("How can I assist you today?", "")
 
 
24
  if st.button("Submit"):
25
  if user_input:
26
  st.write("User: ", user_input)