File size: 3,177 Bytes
f590377
9835d66
56d8c5b
f590377
56d8c5b
9835d66
f590377
56d8c5b
 
 
f590377
56d8c5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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()