NotunBangla / app.py
Junaed59's picture
Update app.py
56d8c5b verified
import gradio as gr
from transformers import pipeline
import time
# Load Bangla model
bangla_ai = pipeline("text2text-generation", model="csebuetnlp/banglat5")
# Bangladesh Flag Colors
BD_GREEN = "#006a4e"
BD_RED = "#f42a41"
# Custom CSS with Animations
custom_css = f"""
footer {{visibility: hidden}}
@import url('https://fonts.maateen.me/kalpurush/font.css');
.bangla-font * {{
font-family: "Kalpurush", "Siyam Rupali", sans-serif !important;
}}
/* Welcome Animation */
@keyframes welcome {{
0% {{ transform: scale(0.8); opacity: 0; }}
100% {{ transform: scale(1); opacity: 1; }}
}}
.welcome-anim {{
animation: welcome 1s ease-out;
}}
/* Thinking Dots */
.thinking-dots {{
display: inline-block;
}}
.thinking-dots span {{
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
background: {BD_GREEN};
margin: 0 2px;
opacity: 0;
}}
.thinking-dots span:nth-child(1) {{
animation: dot-pulse 1.5s infinite;
}}
.thinking-dots span:nth-child(2) {{
animation: dot-pulse 1.5s infinite 0.2s;
}}
.thinking-dots span:nth-child(3) {{
animation: dot-pulse 1.5s infinite 0.4s;
}}
@keyframes dot-pulse {{
0%, 100% {{ opacity: 0.3; transform: translateY(0); }}
50% {{ opacity: 1; transform: translateY(-5px); }}
}}
/* Button Style */
button {{
background: {BD_GREEN} !important;
color: white !important;
}}
button:hover {{
background: {BD_RED} !important;
}}
"""
def chat(message, history):
# Show thinking dots
yield "প্রস্তুত হচ্ছে... <div class='thinking-dots'><span></span><span></span><span></span></div>"
# Simulate processing time
time.sleep(1.5) # Remove this in production
# Get AI response
response = bangla_ai(message, max_length=150)[0]['generated_text']
yield response
with gr.Blocks(
title="নতুন বাংলা AI",
css=custom_css,
theme=gr.themes.Default(primary_hue="green")
) as app:
# Welcome Animation
with gr.Row():
with gr.Column():
gr.HTML("""
<div class="welcome-anim" style="text-align:center">
<img src="logo.png" width="120" style="margin-bottom:10px">
<h1 class="bangla-font" style="color:#006a4e; margin-bottom:0">নতুন বাংলা AI</h1>
<p class="bangla-font" style="color:#f42a41">জাতীয় জ্ঞান সহায়ক</p>
</div>
""")
# Chat Interface
gr.ChatInterface(
fn=chat,
chatbot=gr.Chatbot(
avatar_images=(None, "logo.png"),
bubble_full_width=False,
render_markdown=True
),
textbox=gr.Textbox(
placeholder="এখানে বাংলায় প্রশ্ন লিখুন...",
label=""
),
submit_btn=gr.Button("প্রেরণ", variant="primary"),
examples=[
["বাংলাদেশের স্বাধীনতা দিবস কবে?"],
["রবীন্দ্রনাথ ঠাকুর কে ছিলেন?"]
]
)
app.launch()