Commit
Β·
269a1cc
1
Parent(s):
ff2a969
return back to the old version
Browse files
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(
|
| 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 |
-
|
| 153 |
-
|
|
|
|
| 154 |
to translate English sentences into appropriate emoji sequences.
|
| 155 |
-
</div>
|
| 156 |
|
| 157 |
-
|
| 158 |
-
|
| 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
|
| 169 |
placeholder="Type something like: I am happy today...",
|
| 170 |
-
lines=
|
| 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
|
| 180 |
-
info="
|
| 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="π
|
| 194 |
-
lines=
|
| 195 |
-
|
| 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 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
</ul>
|
| 240 |
-
</div>
|
| 241 |
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
</div>
|
| 250 |
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 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 |
|