Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -80,16 +80,24 @@ def classify_text(input_text, k=20):
|
|
80 |
|
81 |
# Construct OpenAI prompt
|
82 |
prompt = f"""
|
83 |
-
You are a mental health specialist.
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
87 |
"{input_text}"
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
93 |
"""
|
94 |
|
95 |
try:
|
@@ -101,19 +109,19 @@ def classify_text(input_text, k=20):
|
|
101 |
model="gpt-4",
|
102 |
temperature=0,
|
103 |
)
|
104 |
-
|
|
|
105 |
|
106 |
-
#
|
107 |
-
content = response.choices[0].message.content
|
108 |
-
print("Response Content:", content)
|
109 |
return json.loads(content)
|
110 |
except json.JSONDecodeError:
|
111 |
-
print("Failed to decode JSON
|
112 |
-
return {"error":
|
113 |
except Exception as e:
|
114 |
print(f"Error occurred: {e}")
|
115 |
return {"error": str(e)}
|
116 |
|
|
|
117 |
# Gradio Interface
|
118 |
interface = gr.Interface(
|
119 |
fn=classify_text,
|
|
|
80 |
|
81 |
# Construct OpenAI prompt
|
82 |
prompt = f"""
|
83 |
+
You are a mental health specialist. Analyze the provided text and classify it into one or more of the following categories: Stress, Anxiety, Depression, or Other.
|
84 |
+
|
85 |
+
Respond **only** in JSON format with the following keys:
|
86 |
+
- Ground_Truth_Stress: 1 or 0
|
87 |
+
- Ground_Truth_Anxiety: 1 or 0
|
88 |
+
- Ground_Truth_Depression: 1 or 0
|
89 |
+
- Ground_Truth_Other_binary: 1 or 0
|
90 |
+
|
91 |
+
Here is the text to classify:
|
92 |
"{input_text}"
|
93 |
+
|
94 |
+
### Example Response:
|
95 |
+
{{
|
96 |
+
"Ground_Truth_Stress": 0,
|
97 |
+
"Ground_Truth_Anxiety": 1,
|
98 |
+
"Ground_Truth_Depression": 0,
|
99 |
+
"Ground_Truth_Other_binary": 0
|
100 |
+
}}
|
101 |
"""
|
102 |
|
103 |
try:
|
|
|
109 |
model="gpt-4",
|
110 |
temperature=0,
|
111 |
)
|
112 |
+
content = response.choices[0].message.content.strip()
|
113 |
+
print("Raw Response Content:", content)
|
114 |
|
115 |
+
# Attempt to parse as JSON
|
|
|
|
|
116 |
return json.loads(content)
|
117 |
except json.JSONDecodeError:
|
118 |
+
print("Failed to decode JSON. Returning raw content.")
|
119 |
+
return {"error": "Failed to decode JSON", "raw_response": content}
|
120 |
except Exception as e:
|
121 |
print(f"Error occurred: {e}")
|
122 |
return {"error": str(e)}
|
123 |
|
124 |
+
|
125 |
# Gradio Interface
|
126 |
interface = gr.Interface(
|
127 |
fn=classify_text,
|