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 "প্রস্তুত হচ্ছে...
" # 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("""

নতুন বাংলা AI

জাতীয় জ্ঞান সহায়ক

""") # 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()