Spaces:
Runtime error
Runtime error
| from transformers import pipeline | |
| import requests | |
| import gradio as gr | |
| # Load emotion detection model | |
| emotion_model = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", top_k=1) | |
| # Mappings | |
| mood_mapping = { | |
| 'joy': 'happy', | |
| 'neutral': 'calm', | |
| 'sadness': 'calm', | |
| 'fear': 'professional', | |
| 'anger': 'energetic', | |
| 'surprise': 'energetic', | |
| 'disgust': 'professional' | |
| } | |
| ui_styles = { | |
| 'happy': { | |
| 'font': 'Comic Neue', | |
| 'tip': 'Use bright colors, rounded buttons, playful layout.' | |
| }, | |
| 'calm': { | |
| 'font': 'Lato', | |
| 'tip': 'Use cool tones, white space, soft shadows.' | |
| }, | |
| 'energetic': { | |
| 'font': 'Bebas Neue', | |
| 'tip': 'Use bold colors, sharp edges, vibrant CTAs.' | |
| }, | |
| 'professional': { | |
| 'font': 'Roboto', | |
| 'tip': 'Use clean layouts, neutral tones, consistent spacing.' | |
| } | |
| } | |
| # Main Function | |
| def mood_to_ui(text): | |
| result = emotion_model(text)[0][0] | |
| emotion = result['label'].lower() | |
| mood = mood_mapping.get(emotion, 'calm') | |
| style = ui_styles[mood] | |
| # Colormind API | |
| try: | |
| color_data = {"model": "default"} | |
| color_res = requests.post("http://colormind.io/api/", json=color_data) | |
| colors = color_res.json()['result'] | |
| except: | |
| colors = [] | |
| return { | |
| "Emotion": emotion, | |
| "Mood": mood, | |
| "Font": style['font'], | |
| "UI Tip": style['tip'], | |
| "Color Palette": str(colors) | |
| } | |
| # Gradio UI | |
| iface = gr.Interface(fn=mood_to_ui, inputs="text", outputs="json", title="Mood to UI Generator") | |
| iface.launch() | |