Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,15 +19,15 @@ async def classify_emotion(message: str):
|
|
19 |
json_results = json.dumps(results, indent=4)
|
20 |
return json_results
|
21 |
except Exception as e:
|
22 |
-
return {"error": str(e)}
|
23 |
|
24 |
-
def process_inputs(message: str):
|
25 |
try:
|
26 |
main.disabled = True
|
27 |
|
28 |
# Perform emotion classification
|
29 |
yield "##### βοΈ Classifying emotions..."
|
30 |
-
results =
|
31 |
|
32 |
# Display results
|
33 |
yield "##### π Emotion Classification Results:"
|
@@ -36,8 +36,7 @@ def process_inputs(message: str):
|
|
36 |
finally:
|
37 |
main.disabled = False
|
38 |
|
39 |
-
|
40 |
-
# create widgets
|
41 |
message_input = pn.widgets.TextInput(
|
42 |
name="Enter a message for emotion classification",
|
43 |
placeholder="Type your message here...",
|
@@ -46,23 +45,24 @@ message_input = pn.widgets.TextInput(
|
|
46 |
|
47 |
classify_button = pn.widgets.Button(name="Classify Emotion", button_type="primary")
|
48 |
|
49 |
-
#
|
50 |
def on_button_click(event):
|
51 |
message = message_input.value
|
52 |
if message:
|
53 |
-
|
54 |
-
|
|
|
55 |
|
56 |
classify_button.on_click(on_button_click)
|
57 |
|
58 |
-
#
|
59 |
panel_content = pn.Column(
|
60 |
"### π Emotion Classification",
|
61 |
message_input,
|
62 |
classify_button,
|
63 |
)
|
64 |
|
65 |
-
#
|
66 |
footer_row = pn.Row(pn.Spacer(), align="center")
|
67 |
for icon, url in ICON_URLS.items():
|
68 |
href_button = pn.widgets.Button(icon=icon, width=35, height=35)
|
@@ -70,7 +70,7 @@ for icon, url in ICON_URLS.items():
|
|
70 |
footer_row.append(href_button)
|
71 |
footer_row.append(pn.Spacer())
|
72 |
|
73 |
-
#
|
74 |
main = pn.Column(
|
75 |
panel_content,
|
76 |
footer_row,
|
|
|
19 |
json_results = json.dumps(results, indent=4)
|
20 |
return json_results
|
21 |
except Exception as e:
|
22 |
+
return json.dumps({"error": str(e)}, indent=4)
|
23 |
|
24 |
+
async def process_inputs(message: str):
|
25 |
try:
|
26 |
main.disabled = True
|
27 |
|
28 |
# Perform emotion classification
|
29 |
yield "##### βοΈ Classifying emotions..."
|
30 |
+
results = await classify_emotion(message)
|
31 |
|
32 |
# Display results
|
33 |
yield "##### π Emotion Classification Results:"
|
|
|
36 |
finally:
|
37 |
main.disabled = False
|
38 |
|
39 |
+
# Create widgets
|
|
|
40 |
message_input = pn.widgets.TextInput(
|
41 |
name="Enter a message for emotion classification",
|
42 |
placeholder="Type your message here...",
|
|
|
45 |
|
46 |
classify_button = pn.widgets.Button(name="Classify Emotion", button_type="primary")
|
47 |
|
48 |
+
# Define callback function for button click
|
49 |
def on_button_click(event):
|
50 |
message = message_input.value
|
51 |
if message:
|
52 |
+
panel_content[:] = []
|
53 |
+
async_generator = process_inputs(message)
|
54 |
+
pn.state.execute(async_generator, panel_content.extend)
|
55 |
|
56 |
classify_button.on_click(on_button_click)
|
57 |
|
58 |
+
# Create main panel content
|
59 |
panel_content = pn.Column(
|
60 |
"### π Emotion Classification",
|
61 |
message_input,
|
62 |
classify_button,
|
63 |
)
|
64 |
|
65 |
+
# Add footer
|
66 |
footer_row = pn.Row(pn.Spacer(), align="center")
|
67 |
for icon, url in ICON_URLS.items():
|
68 |
href_button = pn.widgets.Button(icon=icon, width=35, height=35)
|
|
|
70 |
footer_row.append(href_button)
|
71 |
footer_row.append(pn.Spacer())
|
72 |
|
73 |
+
# Create dashboard
|
74 |
main = pn.Column(
|
75 |
panel_content,
|
76 |
footer_row,
|