mohamedmostafa259 commited on
Commit
269a1cc
Β·
1 Parent(s): ff2a969

return back to the old version

Browse files
Files changed (1) hide show
  1. app.py +32 -147
app.py CHANGED
@@ -51,153 +51,47 @@ def translate_to_emoji(text, creativity_level=0):
51
  except Exception as e:
52
  return f"❌ Error: {str(e)}"
53
 
54
- # Custom CSS for enhanced styling
55
- custom_css = """
56
- #title {
57
- text-align: center;
58
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
59
- padding: 2rem;
60
- border-radius: 10px;
61
- margin-bottom: 2rem;
62
- }
63
-
64
- #title h1 {
65
- color: white;
66
- font-size: 3em !important;
67
- margin-bottom: 0.5rem;
68
- text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
69
- }
70
-
71
- .description {
72
- font-size: 1.3em !important;
73
- line-height: 1.8 !important;
74
- color: #2d3748;
75
- margin: 1.5rem 0;
76
- }
77
-
78
- .examples-text {
79
- font-size: 1.2em !important;
80
- color: #4a5568;
81
- font-weight: 500;
82
- }
83
-
84
- .placeholder-large::placeholder {
85
- font-size: 1.1em !important;
86
- }
87
-
88
- .info-section {
89
- background: #f7fafc;
90
- padding: 1.5rem;
91
- border-radius: 8px;
92
- margin: 1rem 0;
93
- border-left: 4px solid #667eea;
94
- }
95
-
96
- .info-section h3 {
97
- color: #667eea;
98
- font-size: 1.5em !important;
99
- margin-bottom: 1rem;
100
- }
101
-
102
- .info-section ul {
103
- font-size: 1.2em !important;
104
- line-height: 2 !important;
105
- }
106
-
107
- .info-section li {
108
- margin: 0.8rem 0;
109
- }
110
-
111
- .info-section a {
112
- color: #667eea;
113
- font-weight: 600;
114
- text-decoration: none;
115
- }
116
-
117
- .info-section a:hover {
118
- text-decoration: underline;
119
- }
120
-
121
- .creativity-label {
122
- font-size: 1.15em !important;
123
- }
124
-
125
- #output-box {
126
- font-size: 2.5em !important;
127
- text-align: center;
128
- background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
129
- border-radius: 10px;
130
- padding: 1rem;
131
- }
132
-
133
- .translate-btn {
134
- font-size: 1.2em !important;
135
- padding: 0.8rem 2rem !important;
136
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
137
- border: none !important;
138
- font-weight: 600 !important;
139
- }
140
- """
141
-
142
  # Create Gradio interface
143
- with gr.Blocks(title="🎭 Emoji Translator", theme=gr.themes.Soft(primary_hue="purple"), css=custom_css) as demo:
144
-
145
- # Title Section
146
- with gr.Column(elem_id="title"):
147
- gr.Markdown("# 🎭 BART Emoji Translator")
148
-
149
- # Description
150
  gr.Markdown(
151
  """
152
- <div class="description">
153
- <strong>Transform your text into emojis!</strong> This model uses <em>curriculum learning</em> and <em>LoRA fine-tuning</em>
 
154
  to translate English sentences into appropriate emoji sequences.
155
- </div>
156
 
157
- <div class="examples-text">
158
- <strong>πŸ’‘ Examples to try:</strong> "I am happy", "I eat dinner with my family", or "I feel misunderstood"
159
- </div>
160
- """,
161
- elem_classes="description"
162
  )
163
 
164
- # Main Interface
165
  with gr.Row():
166
  with gr.Column(scale=2):
167
  text_input = gr.Textbox(
168
- label="πŸ“ Enter Your Text",
169
  placeholder="Type something like: I am happy today...",
170
- lines=4,
171
- elem_classes="placeholder-large"
172
  )
173
 
 
174
  creativity = gr.Slider(
175
  minimum=0,
176
  maximum=2,
177
  value=1,
178
  step=1,
179
- label="🎨 Creativity Level",
180
- info="Choose your translation style: 0 = Strict & Accurate | 1 = Balanced | 2 = Creative (more randomness, may be less accurate)",
181
- elem_classes="creativity-label"
182
  )
183
 
184
- translate_btn = gr.Button(
185
- "✨ Translate to Emojis",
186
- variant="primary",
187
- size="lg",
188
- elem_classes="translate-btn"
189
- )
190
 
191
  with gr.Column(scale=1):
192
  emoji_output = gr.Textbox(
193
- label="πŸŽ‰ Your Emoji Translation",
194
- lines=6,
195
- elem_id="output-box",
196
- show_copy_button=True
197
  )
198
 
199
  # Example inputs
200
- gr.Markdown("### πŸ“‹ Quick Examples")
201
  gr.Examples(
202
  examples=[
203
  ["I am happy", 0],
@@ -226,36 +120,27 @@ with gr.Blocks(title="🎭 Emoji Translator", theme=gr.themes.Soft(primary_hue="
226
  outputs=emoji_output
227
  )
228
 
229
- # Model Information Section
230
  gr.Markdown(
231
  """
232
- <div class="info-section">
233
- <h3>πŸ“š Model Architecture & Training</h3>
234
- <ul>
235
- <li><strong>Base Model:</strong> BART-Large with LoRA fine-tuning</li>
236
- <li><strong>Training Method:</strong> 6-phase curriculum learning with strategic data retention</li>
237
- <li><strong>LoRA Parameters:</strong> Rank 128, Alpha 256</li>
238
- <li><strong>Dataset Strategy:</strong> Progressive difficulty from single emojis to complex sequences</li>
239
- </ul>
240
- </div>
241
 
242
- <div class="info-section">
243
- <h3>πŸ”— Resources & Links</h3>
244
- <ul>
245
- <li><a href="https://huggingface.co/mohamedmostafa259/bart-emoji-translator" target="_blank">πŸ€— Model on HuggingFace</a></li>
246
- <li><a href="https://www.kaggle.com/code/mohamedmostafa259/emoji-translator-curriculum-learning" target="_blank">πŸ’» Training Code on Kaggle</a></li>
247
- <li><a href="https://www.kaggle.com/datasets/mohamedmostafa259/english-to-emoji" target="_blank">πŸ“Š Dataset on Kaggle</a></li>
248
- </ul>
249
- </div>
250
 
251
- <div class="info-section">
252
- <h3>⚠️ Model Limitations</h3>
253
- <ul>
254
- <li><strong>Optimal performance:</strong> Works best with English text under 32 tokens</li>
255
- <li><strong>Emoji coverage:</strong> May not recognize very rare or newly created emojis</li>
256
- <li><strong>Complexity handling:</strong> Performance varies with text complexity and abstraction level</li>
257
- </ul>
258
- </div>
259
  """
260
  )
261
 
 
51
  except Exception as e:
52
  return f"❌ Error: {str(e)}"
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  # Create Gradio interface
55
+ with gr.Blocks(title="🎭 Emoji Translator", theme=gr.themes.Soft()) as demo:
 
 
 
 
 
 
56
  gr.Markdown(
57
  """
58
+ # 🎭 BART Emoji Translator
59
+
60
+ Transform your text into emojis! This model uses curriculum learning and LoRA fine-tuning
61
  to translate English sentences into appropriate emoji sequences.
 
62
 
63
+ **Examples:** Try "I am happy", "I eat dinner with my family", or "I feel misunderstood"
64
+ """
 
 
 
65
  )
66
 
 
67
  with gr.Row():
68
  with gr.Column(scale=2):
69
  text_input = gr.Textbox(
70
+ label="πŸ“ Enter your text",
71
  placeholder="Type something like: I am happy today...",
72
+ lines=3
 
73
  )
74
 
75
+ # --- Creativity Slider (0, 1, 2) ---
76
  creativity = gr.Slider(
77
  minimum=0,
78
  maximum=2,
79
  value=1,
80
  step=1,
81
+ label="🎨 Creativity",
82
+ info="0 = strict, 1 = balanced, 2 = creative"
 
83
  )
84
 
85
+ translate_btn = gr.Button("✨ Translate to Emojis", variant="primary")
 
 
 
 
 
86
 
87
  with gr.Column(scale=1):
88
  emoji_output = gr.Textbox(
89
+ label="πŸŽ‰ Emoji Translation",
90
+ lines=3,
91
+ scale=2
 
92
  )
93
 
94
  # Example inputs
 
95
  gr.Examples(
96
  examples=[
97
  ["I am happy", 0],
 
120
  outputs=emoji_output
121
  )
122
 
 
123
  gr.Markdown(
124
  """
125
+ ---
126
+ ### πŸ“š Model Information
127
+
128
+ - **Model:** BART-Large with LoRA fine-tuning
129
+ - **Training:** 6-phase curriculum learning with strategic data retention
130
+ - **Parameters:** 128 LoRA rank, 256 alpha
131
+ - **Dataset:** Progressive difficulty from single emojis to complex sequences
 
 
132
 
133
+ ### πŸ”— Links
134
+
135
+ - [πŸ€— Model on HuggingFace](https://huggingface.co/mohamedmostafa259/bart-emoji-translator)
136
+ - [πŸ’» Training Code](https://www.kaggle.com/code/mohamedmostafa259/emoji-translator-curriculum-learning)
137
+ - [πŸ“Š Dataset](https://www.kaggle.com/datasets/mohamedmostafa259/english-to-emoji)
138
+
139
+ ### ⚠️ Limitations
 
140
 
141
+ - Works best with English text under 32 tokens
142
+ - May not recognize very rare or newly created emojis
143
+ - Performance varies with text complexity
 
 
 
 
 
144
  """
145
  )
146