Junaed59 commited on
Commit
56d8c5b
·
verified ·
1 Parent(s): 84d3395

Update app.py

Browse files

![1000005109.png](https://cdn-uploads.huggingface.co/production/uploads/6866711c4357f5b535fb9015/_MgKounOUjjen6eRNWrFD.png)

Files changed (1) hide show
  1. app.py +107 -4
app.py CHANGED
@@ -1,10 +1,113 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
4
- # Load model
5
  bangla_ai = pipeline("text2text-generation", model="csebuetnlp/banglat5")
6
 
7
- def chat(message):
8
- return bangla_ai(message, max_length=100)[0]['generated_text']
 
9
 
10
- gr.ChatInterface(chat, title="NOTUNBANGLA AI").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import time
4
 
5
+ # Load Bangla model
6
  bangla_ai = pipeline("text2text-generation", model="csebuetnlp/banglat5")
7
 
8
+ # Bangladesh Flag Colors
9
+ BD_GREEN = "#006a4e"
10
+ BD_RED = "#f42a41"
11
 
12
+ # Custom CSS with Animations
13
+ custom_css = f"""
14
+ footer {{visibility: hidden}}
15
+ @import url('https://fonts.maateen.me/kalpurush/font.css');
16
+ .bangla-font * {{
17
+ font-family: "Kalpurush", "Siyam Rupali", sans-serif !important;
18
+ }}
19
+
20
+ /* Welcome Animation */
21
+ @keyframes welcome {{
22
+ 0% {{ transform: scale(0.8); opacity: 0; }}
23
+ 100% {{ transform: scale(1); opacity: 1; }}
24
+ }}
25
+ .welcome-anim {{
26
+ animation: welcome 1s ease-out;
27
+ }}
28
+
29
+ /* Thinking Dots */
30
+ .thinking-dots {{
31
+ display: inline-block;
32
+ }}
33
+ .thinking-dots span {{
34
+ display: inline-block;
35
+ width: 8px;
36
+ height: 8px;
37
+ border-radius: 50%;
38
+ background: {BD_GREEN};
39
+ margin: 0 2px;
40
+ opacity: 0;
41
+ }}
42
+ .thinking-dots span:nth-child(1) {{
43
+ animation: dot-pulse 1.5s infinite;
44
+ }}
45
+ .thinking-dots span:nth-child(2) {{
46
+ animation: dot-pulse 1.5s infinite 0.2s;
47
+ }}
48
+ .thinking-dots span:nth-child(3) {{
49
+ animation: dot-pulse 1.5s infinite 0.4s;
50
+ }}
51
+ @keyframes dot-pulse {{
52
+ 0%, 100% {{ opacity: 0.3; transform: translateY(0); }}
53
+ 50% {{ opacity: 1; transform: translateY(-5px); }}
54
+ }}
55
+
56
+ /* Button Style */
57
+ button {{
58
+ background: {BD_GREEN} !important;
59
+ color: white !important;
60
+ }}
61
+ button:hover {{
62
+ background: {BD_RED} !important;
63
+ }}
64
+ """
65
+
66
+ def chat(message, history):
67
+ # Show thinking dots
68
+ yield "প্রস্তুত হচ্ছে... <div class='thinking-dots'><span></span><span></span><span></span></div>"
69
+
70
+ # Simulate processing time
71
+ time.sleep(1.5) # Remove this in production
72
+
73
+ # Get AI response
74
+ response = bangla_ai(message, max_length=150)[0]['generated_text']
75
+ yield response
76
+
77
+ with gr.Blocks(
78
+ title="নতুন বাংলা AI",
79
+ css=custom_css,
80
+ theme=gr.themes.Default(primary_hue="green")
81
+ ) as app:
82
+
83
+ # Welcome Animation
84
+ with gr.Row():
85
+ with gr.Column():
86
+ gr.HTML("""
87
+ <div class="welcome-anim" style="text-align:center">
88
+ <img src="logo.png" width="120" style="margin-bottom:10px">
89
+ <h1 class="bangla-font" style="color:#006a4e; margin-bottom:0">নতুন বাংলা AI</h1>
90
+ <p class="bangla-font" style="color:#f42a41">জাতীয় জ্ঞান সহায়ক</p>
91
+ </div>
92
+ """)
93
+
94
+ # Chat Interface
95
+ gr.ChatInterface(
96
+ fn=chat,
97
+ chatbot=gr.Chatbot(
98
+ avatar_images=(None, "logo.png"),
99
+ bubble_full_width=False,
100
+ render_markdown=True
101
+ ),
102
+ textbox=gr.Textbox(
103
+ placeholder="এখানে বাংলায় প্রশ্ন লিখুন...",
104
+ label=""
105
+ ),
106
+ submit_btn=gr.Button("প্রেরণ", variant="primary"),
107
+ examples=[
108
+ ["বাংলাদেশের স্বাধীনতা দিবস কবে?"],
109
+ ["রবীন্দ্রনাথ ঠাকুর কে ছিলেন?"]
110
+ ]
111
+ )
112
+
113
+ app.launch()