Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -107,33 +107,35 @@ def respond(message, history,country):
|
|
| 107 |
# Create a custom Gradio interface using Blocks
|
| 108 |
with gr.Blocks() as demo:
|
| 109 |
gr.Markdown("# π UMatter - Youth Mental Health Support Hub")
|
| 110 |
-
|
| 111 |
with gr.Tabs():
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
| 131 |
gr.ChatInterface(
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
)
|
| 137 |
# Tab 2: Our brand new private journal space
|
| 138 |
with gr.TabItem("π My Private Journal"):
|
| 139 |
gr.Markdown("### π Your Secure Personal Space")
|
|
@@ -162,21 +164,21 @@ with gr.Blocks() as demo:
|
|
| 162 |
|
| 163 |
def save_journal_entry(text):
|
| 164 |
if not text.strip():
|
| 165 |
-
return
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
preview_title = text[:20] + "..." if len(text) > 20 else text
|
| 172 |
-
|
| 173 |
-
# Update the dropdown list with the new entry preview
|
| 174 |
-
return (
|
| 175 |
-
gr.update(value=""), # Clear the writing textbox
|
| 176 |
-
gr.update(value="β
Entry saved successfully!"),
|
| 177 |
-
gr.update(choices=journal_storage, value=text)
|
| 178 |
)
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
|
| 182 |
save_btn.click(
|
|
@@ -184,13 +186,12 @@ save_btn.click(
|
|
| 184 |
inputs=journal_input,
|
| 185 |
outputs=[journal_input, status_output, history_dropdown]
|
| 186 |
)
|
| 187 |
-
|
| 188 |
def view_journal_entry(selected_text):
|
| 189 |
if not selected_text:
|
| 190 |
return gr.update()
|
| 191 |
return gr.update(value=selected_text)
|
| 192 |
|
| 193 |
-
|
| 194 |
fn=view_journal_entry,
|
| 195 |
inputs=history_dropdown,
|
| 196 |
outputs=journal_input
|
|
|
|
| 107 |
# Create a custom Gradio interface using Blocks
|
| 108 |
with gr.Blocks() as demo:
|
| 109 |
gr.Markdown("# π UMatter - Youth Mental Health Support Hub")
|
| 110 |
+
|
| 111 |
with gr.Tabs():
|
| 112 |
+
|
| 113 |
+
with gr.TabItem("π¬ Support Chat"):
|
| 114 |
+
|
| 115 |
+
country_dropdown = gr.Dropdown(
|
| 116 |
+
choices=[
|
| 117 |
+
"United States",
|
| 118 |
+
"India",
|
| 119 |
+
"Canada",
|
| 120 |
+
"United Kingdom",
|
| 121 |
+
"Australia",
|
| 122 |
+
"Germany",
|
| 123 |
+
"France",
|
| 124 |
+
"Japan",
|
| 125 |
+
"Mexico",
|
| 126 |
+
"Brazil",
|
| 127 |
+
"South Korea"
|
| 128 |
+
],
|
| 129 |
+
value="United States",
|
| 130 |
+
label="Select Your Country"
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
gr.ChatInterface(
|
| 134 |
+
fn=respond,
|
| 135 |
+
additional_inputs=[country_dropdown],
|
| 136 |
+
title="UMatter Chat",
|
| 137 |
+
description="Talk to me about anything mental health π"
|
| 138 |
+
)
|
| 139 |
# Tab 2: Our brand new private journal space
|
| 140 |
with gr.TabItem("π My Private Journal"):
|
| 141 |
gr.Markdown("### π Your Secure Personal Space")
|
|
|
|
| 164 |
|
| 165 |
def save_journal_entry(text):
|
| 166 |
if not text.strip():
|
| 167 |
+
return (
|
| 168 |
+
gr.update(),
|
| 169 |
+
gr.update(value="β οΈ Cannot save an empty entry!"),
|
| 170 |
+
gr.update()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
)
|
| 172 |
|
| 173 |
+
journal_storage.append(text)
|
| 174 |
+
|
| 175 |
+
preview_title = text[:20] + "..." if len(text) > 20 else text
|
| 176 |
+
|
| 177 |
+
return (
|
| 178 |
+
gr.update(value=""),
|
| 179 |
+
gr.update(value="β
Entry saved successfully!"),
|
| 180 |
+
gr.update(choices=journal_storage, value=text)
|
| 181 |
+
)
|
| 182 |
|
| 183 |
|
| 184 |
save_btn.click(
|
|
|
|
| 186 |
inputs=journal_input,
|
| 187 |
outputs=[journal_input, status_output, history_dropdown]
|
| 188 |
)
|
|
|
|
| 189 |
def view_journal_entry(selected_text):
|
| 190 |
if not selected_text:
|
| 191 |
return gr.update()
|
| 192 |
return gr.update(value=selected_text)
|
| 193 |
|
| 194 |
+
view_btn.click(
|
| 195 |
fn=view_journal_entry,
|
| 196 |
inputs=history_dropdown,
|
| 197 |
outputs=journal_input
|