King-8's picture
Update app.py
4848695 verified
import gradio as gr
from transformers import pipeline
# Load your fine-tuned model
classifier = pipeline("text-classification", model="King-8/creative-energy-analyzer")
# Define custom label colors
label_colors = {
"inspired": "#FFB703", # bright yellow-orange
"expressive": "#8ECAE6", # sky blue
"curious": "#90BE6D", # green
"stuck": "#FB8500", # orange
"doubtful": "#8338EC", # purple
"drained": "#D62828" # red
}
# Explanations & tips
label_info = {
"inspired": {
"meaning": "You’re bursting with ideas and energy to create.",
"tip": "✨ Keep riding this wave! Capture your ideas quickly so they don’t slip away."
},
"expressive": {
"meaning": "You’re in the flow, freely articulating and experimenting.",
"tip": "🎨 Keep experimenting — your voice is strong and authentic right now."
},
"curious": {
"meaning": "You’re exploring possibilities and open to discovery.",
"tip": "🔍 Follow your curiosity — it often leads to breakthroughs!"
},
"stuck": {
"meaning": "You want to create but feel blocked or unsure.",
"tip": "💡 Try a tiny step forward — even a rough sketch or note counts."
},
"doubtful": {
"meaning": "You’re questioning your skills or the value of your ideas.",
"tip": "💪 Remember: progress matters more than perfection. Keep going!"
},
"drained": {
"meaning": "You’re exhausted or creatively burned out.",
"tip": "🌙 Rest and recharge — creativity returns when you give yourself space."
}
}
# Function to analyze creative energy
def analyze_creativity(text):
results = classifier(text, top_k=6)
# Top prediction
top = results[0]
top_label = top["label"]
top_score = round(top["score"] * 100, 1) # percentage
meaning = label_info[top_label]["meaning"]
tip = label_info[top_label]["tip"]
# Header for top prediction
top_section = f"""
<div style='padding:12px;margin-bottom:10px;border-radius:10px;background:{label_colors[top_label]};color:white;'>
<h2>Predicted: {top_label.capitalize()} ({top_score}%)</h2>
<p><b>{meaning}</b></p>
<p>{tip}</p>
</div>
"""
# Score bars for all labels
bars = ""
for res in results:
label = res["label"]
score = round(res["score"] * 100, 1) # percentage
color = label_colors.get(label, "#CCCCCC")
bars += f"<div style='background:{color};padding:8px;border-radius:8px;margin:3px;color:white;'>"
bars += f"{label}: {score}%</div>"
return top_section + bars
# Gradio interface
demo = gr.Interface(
fn=analyze_creativity,
inputs=gr.Textbox(lines=3, placeholder="Type your creative thoughts here..."),
outputs=gr.HTML(),
title="🎨 Creative Energy Sentiment Classifier",
description="""
This app predicts your **creative energy state** and offers tailored insights:
- 🟡 inspired → Encouragement to capture your spark
- 🔵 expressive → Tips to keep flowing
- 🟢 curious → Guidance to follow your wonder
- 🟠 stuck → Motivation to take small steps
- 🟣 doubtful → Reminders of your worth
- 🔴 drained → Advice to rest and recharge
"""
)
if __name__ == "__main__":
demo.launch()