Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import pandas as pd
|
|
| 5 |
import os
|
| 6 |
import uuid
|
| 7 |
import json
|
|
|
|
| 8 |
|
| 9 |
# Page configuration
|
| 10 |
st.set_page_config(
|
|
@@ -85,6 +86,34 @@ def get_inference_client():
|
|
| 85 |
api_key=api_token,
|
| 86 |
)
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
# Function to analyze journal entries
|
| 89 |
def analyze_journal(entry, model_name="deepseek-ai/DeepSeek-R1"):
|
| 90 |
client = get_inference_client()
|
|
@@ -96,12 +125,13 @@ def analyze_journal(entry, model_name="deepseek-ai/DeepSeek-R1"):
|
|
| 96 |
|
| 97 |
Journal entry: "{entry}"
|
| 98 |
|
| 99 |
-
Please provide:
|
| 100 |
-
|
|
|
|
| 101 |
2. Recurring themes: Note any patterns or important topics mentioned
|
| 102 |
3. Advice: Offer kind, supportive guidance tailored to what was shared
|
| 103 |
|
| 104 |
-
Format your response
|
| 105 |
"""
|
| 106 |
|
| 107 |
completion = client.chat.completions.create(
|
|
@@ -118,22 +148,8 @@ Format your response clearly with these exact headings (Emotional tone, Recurrin
|
|
| 118 |
|
| 119 |
output = completion.choices[0].message.content
|
| 120 |
|
| 121 |
-
#
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
if "Emotional tone:" in output:
|
| 125 |
-
emotional_tone = output.split("Emotional tone:")[1].split("Recurring themes:")[0].strip()
|
| 126 |
-
formatted_output += f"π **Emotional tone:** {emotional_tone}\n\n"
|
| 127 |
-
|
| 128 |
-
if "Recurring themes:" in output:
|
| 129 |
-
themes = output.split("Recurring themes:")[1].split("Advice:")[0].strip()
|
| 130 |
-
formatted_output += f"π **Recurring themes:** {themes}\n\n"
|
| 131 |
-
|
| 132 |
-
if "Advice:" in output:
|
| 133 |
-
advice = output.split("Advice:")[1].strip()
|
| 134 |
-
formatted_output += f"π‘ **Advice:** {advice}"
|
| 135 |
-
|
| 136 |
-
return formatted_output if formatted_output else output
|
| 137 |
|
| 138 |
except Exception as e:
|
| 139 |
st.error(f"API Error: {str(e)}")
|
|
@@ -344,7 +360,4 @@ st.markdown("---")
|
|
| 344 |
st.caption("""
|
| 345 |
**Disclaimer**: This app is for educational purposes only and is not a substitute for professional mental health advice, diagnosis, or treatment.
|
| 346 |
Always seek the advice of your physician or other qualified health provider with any questions regarding a medical condition.
|
| 347 |
-
""")
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
|
|
|
| 5 |
import os
|
| 6 |
import uuid
|
| 7 |
import json
|
| 8 |
+
import re
|
| 9 |
|
| 10 |
# Page configuration
|
| 11 |
st.set_page_config(
|
|
|
|
| 86 |
api_key=api_token,
|
| 87 |
)
|
| 88 |
|
| 89 |
+
# Clean the output to remove thinking process
|
| 90 |
+
def clean_output(text):
|
| 91 |
+
# Extract only the parts after the headings
|
| 92 |
+
cleaned_text = ""
|
| 93 |
+
|
| 94 |
+
# Extract Emotional tone section
|
| 95 |
+
if "Emotional tone:" in text:
|
| 96 |
+
match = re.search(r'Emotional tone:(.*?)(?:Recurring themes:|$)', text, re.DOTALL)
|
| 97 |
+
if match:
|
| 98 |
+
emotional_tone = match.group(1).strip()
|
| 99 |
+
cleaned_text += f"π **Emotional tone:** {emotional_tone}\n\n"
|
| 100 |
+
|
| 101 |
+
# Extract Recurring themes section
|
| 102 |
+
if "Recurring themes:" in text:
|
| 103 |
+
match = re.search(r'Recurring themes:(.*?)(?:Advice:|$)', text, re.DOTALL)
|
| 104 |
+
if match:
|
| 105 |
+
themes = match.group(1).strip()
|
| 106 |
+
cleaned_text += f"π **Recurring themes:** {themes}\n\n"
|
| 107 |
+
|
| 108 |
+
# Extract Advice section
|
| 109 |
+
if "Advice:" in text:
|
| 110 |
+
match = re.search(r'Advice:(.*?)$', text, re.DOTALL)
|
| 111 |
+
if match:
|
| 112 |
+
advice = match.group(1).strip()
|
| 113 |
+
cleaned_text += f"π‘ **Advice:** {advice}"
|
| 114 |
+
|
| 115 |
+
return cleaned_text if cleaned_text else text
|
| 116 |
+
|
| 117 |
# Function to analyze journal entries
|
| 118 |
def analyze_journal(entry, model_name="deepseek-ai/DeepSeek-R1"):
|
| 119 |
client = get_inference_client()
|
|
|
|
| 125 |
|
| 126 |
Journal entry: "{entry}"
|
| 127 |
|
| 128 |
+
Please provide the following analysis directly, without explaining your thinking process:
|
| 129 |
+
|
| 130 |
+
1. Emotional tone: Identify the primary emotions expressed in the entry
|
| 131 |
2. Recurring themes: Note any patterns or important topics mentioned
|
| 132 |
3. Advice: Offer kind, supportive guidance tailored to what was shared
|
| 133 |
|
| 134 |
+
Format your response with only these three sections, using the exact headings: "Emotional tone:", "Recurring themes:", and "Advice:". Do not include any additional explanations or thinking.
|
| 135 |
"""
|
| 136 |
|
| 137 |
completion = client.chat.completions.create(
|
|
|
|
| 148 |
|
| 149 |
output = completion.choices[0].message.content
|
| 150 |
|
| 151 |
+
# Clean the output to remove any thinking process
|
| 152 |
+
return clean_output(output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
except Exception as e:
|
| 155 |
st.error(f"API Error: {str(e)}")
|
|
|
|
| 360 |
st.caption("""
|
| 361 |
**Disclaimer**: This app is for educational purposes only and is not a substitute for professional mental health advice, diagnosis, or treatment.
|
| 362 |
Always seek the advice of your physician or other qualified health provider with any questions regarding a medical condition.
|
| 363 |
+
""")
|
|
|
|
|
|
|
|
|