Spaces:
Sleeping
Sleeping
File size: 2,005 Bytes
1b3030e 111bafe 1b3030e 25c0862 111bafe 1b3030e 111bafe 7282520 111bafe 1b3030e 82d2d9a 1b3030e 1794f59 111bafe 25c0862 111bafe 1b3030e 1794f59 1b3030e 25c0862 111bafe 1794f59 1b3030e 111bafe 1b3030e 1794f59 1b3030e 25c0862 1b3030e 111bafe 1794f59 1b3030e 111bafe 1794f59 111bafe 1794f59 1b3030e 111bafe 1b3030e 111bafe 1b3030e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
import json
import panel as pn
from sentrifyai import api
import asyncio
pn.extension(sizing_mode="stretch_width")
ICON_URLS = {
}
async def classify_emotion(message: str):
emotions = api.Emotions()
try:
results = emotions.emotion(model_slug='Emotion-1.0', message=message)
json_results = json.dumps(results, indent=4)
return json_results
except Exception as e:
return json.dumps({"error": str(e)}, indent=4)
async def process_inputs(message: str, panel_content):
try:
main.disabled = True
results = await classify_emotion(message)
# Display results
panel_content.append("##### π Emotion Classification Results:")
panel_content.append(results)
finally:
main.disabled = False
# Create widgets
message_input = pn.widgets.TextInput(
name="Enter a message for emotion classification",
placeholder="Type your message here...",
sizing_mode="stretch_width"
)
classify_button = pn.widgets.Button(name="Classify Emotion", button_type="primary")
# Define callback function for button click
def on_button_click(event):
message = message_input.value
if message:
panel_content.clear()
asyncio.create_task(process_inputs(message, panel_content))
classify_button.on_click(on_button_click)
# Create main panel content
panel_content = pn.Column(
"### π Emotion Classification",
message_input,
classify_button,
)
# Add footer
footer_row = pn.Row(pn.Spacer(), align="center")
for icon, url in ICON_URLS.items():
href_button = pn.widgets.Button(icon=icon, width=35, height=35)
href_button.js_on_click(code=f"window.open('{url}')")
footer_row.append(href_button)
footer_row.append(pn.Spacer())
# Create dashboard
main = pn.Column(
panel_content,
footer_row,
)
title = "Emotion Classification"
pn.template.MaterialTemplate(
title=title,
main=main,
header_background="#F08080",
).servable(title=title)
|