tahirsher commited on
Commit
87a519d
·
verified ·
1 Parent(s): 33e73ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -10
app.py CHANGED
@@ -51,7 +51,7 @@ def load_counseling_dataset():
51
 
52
  dataset = load_counseling_dataset()
53
 
54
- # Load a Hugging Face-compatible text-generation model (Open Access Alternative)
55
  @st.cache_resource
56
  def load_text_generation_model():
57
  return pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")
@@ -65,12 +65,21 @@ Welcome to the Mental Health Counseling Chat application.
65
  This platform is designed to provide supportive, positive, and encouraging responses based on mental health counseling expertise.
66
  """)
67
 
 
 
 
 
 
 
 
 
 
68
  # Explore dataset for additional context or resources (optional)
69
  if st.checkbox("Show Example Questions and Answers from Dataset"):
70
  sample = dataset["train"].shuffle(seed=42).select(range(3)) # Display 3 random samples
71
  for example in sample:
72
- st.markdown(f"**Question:** {example['context']}")
73
- st.markdown(f"**Answer:** {example['response']}")
74
  st.markdown("---")
75
 
76
  # User input for mental health concerns
@@ -78,13 +87,16 @@ user_input = st.text_area("Your question or concern:", placeholder="Type here...
78
 
79
  if st.button("Get Supportive Response"):
80
  if user_input.strip():
81
- # Generate response using the model
82
- prompt = f"User: {user_input}\nCounselor:"
83
- response = text_generator(prompt, max_length=200, num_return_sequences=1)
84
- counselor_reply = response[0]["generated_text"].split("Counselor:")[-1].strip()
85
-
86
- st.subheader("Counselor's Response:")
87
- st.write(counselor_reply)
 
 
 
88
  else:
89
  st.error("Please enter a question or concern to receive a response.")
90
 
 
51
 
52
  dataset = load_counseling_dataset()
53
 
54
+ # Load text-generation model
55
  @st.cache_resource
56
  def load_text_generation_model():
57
  return pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")
 
65
  This platform is designed to provide supportive, positive, and encouraging responses based on mental health counseling expertise.
66
  """)
67
 
68
+ # Check dataset columns
69
+ st.markdown("### Dataset Structure")
70
+ column_names = dataset["train"].column_names
71
+ st.write(f"Columns available in dataset: {column_names}")
72
+
73
+ # Assuming "question" and "answer" columns exist; adjust as per dataset
74
+ question_col = "question" if "question" in column_names else column_names[0]
75
+ answer_col = "answer" if "answer" in column_names else column_names[1]
76
+
77
  # Explore dataset for additional context or resources (optional)
78
  if st.checkbox("Show Example Questions and Answers from Dataset"):
79
  sample = dataset["train"].shuffle(seed=42).select(range(3)) # Display 3 random samples
80
  for example in sample:
81
+ st.markdown(f"**Question:** {example[question_col]}")
82
+ st.markdown(f"**Answer:** {example[answer_col]}")
83
  st.markdown("---")
84
 
85
  # User input for mental health concerns
 
87
 
88
  if st.button("Get Supportive Response"):
89
  if user_input.strip():
90
+ try:
91
+ # Generate response using the model
92
+ prompt = f"User: {user_input}\nCounselor:"
93
+ response = text_generator(prompt, max_length=200, num_return_sequences=1)
94
+ counselor_reply = response[0]["generated_text"].split("Counselor:")[-1].strip()
95
+
96
+ st.subheader("Counselor's Response:")
97
+ st.write(counselor_reply)
98
+ except Exception as e:
99
+ st.error(f"An error occurred while generating the response: {e}")
100
  else:
101
  st.error("Please enter a question or concern to receive a response.")
102