Mano5108 commited on
Commit
8373f26
·
verified ·
1 Parent(s): 869c11d

Upload app (1).py

Browse files
Files changed (1) hide show
  1. app (1).py +63 -0
app (1).py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import requests
3
+ import gradio as gr
4
+
5
+ # Load emotion detection model
6
+ emotion_model = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", top_k=1)
7
+
8
+ # Mappings
9
+ mood_mapping = {
10
+ 'joy': 'happy',
11
+ 'neutral': 'calm',
12
+ 'sadness': 'calm',
13
+ 'fear': 'professional',
14
+ 'anger': 'energetic',
15
+ 'surprise': 'energetic',
16
+ 'disgust': 'professional'
17
+ }
18
+
19
+ ui_styles = {
20
+ 'happy': {
21
+ 'font': 'Comic Neue',
22
+ 'tip': 'Use bright colors, rounded buttons, playful layout.'
23
+ },
24
+ 'calm': {
25
+ 'font': 'Lato',
26
+ 'tip': 'Use cool tones, white space, soft shadows.'
27
+ },
28
+ 'energetic': {
29
+ 'font': 'Bebas Neue',
30
+ 'tip': 'Use bold colors, sharp edges, vibrant CTAs.'
31
+ },
32
+ 'professional': {
33
+ 'font': 'Roboto',
34
+ 'tip': 'Use clean layouts, neutral tones, consistent spacing.'
35
+ }
36
+ }
37
+
38
+ # Main Function
39
+ def mood_to_ui(text):
40
+ result = emotion_model(text)[0][0]
41
+ emotion = result['label'].lower()
42
+ mood = mood_mapping.get(emotion, 'calm')
43
+ style = ui_styles[mood]
44
+
45
+ # Colormind API
46
+ try:
47
+ color_data = {"model": "default"}
48
+ color_res = requests.post("http://colormind.io/api/", json=color_data)
49
+ colors = color_res.json()['result']
50
+ except:
51
+ colors = []
52
+
53
+ return {
54
+ "Emotion": emotion,
55
+ "Mood": mood,
56
+ "Font": style['font'],
57
+ "UI Tip": style['tip'],
58
+ "Color Palette": str(colors)
59
+ }
60
+
61
+ # Gradio UI
62
+ iface = gr.Interface(fn=mood_to_ui, inputs="text", outputs="json", title="Mood to UI Generator")
63
+ iface.launch()