File size: 1,683 Bytes
8373f26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()