sanzanalora commited on
Commit
ae192d1
·
verified ·
1 Parent(s): fee3c3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -49
app.py CHANGED
@@ -35,19 +35,9 @@ def paraphrase_text(input_text):
35
  outputs = paraphrase_model.generate(**inputs)
36
  return paraphrase_tokenizer.decode(outputs[0], skip_special_tokens=True)
37
 
38
- # Process input based on task
39
- def process_text(text, task):
40
- task_funcs = {
41
- "Translate English to Bengali": translate_text_en_bn,
42
- "Translate Bengali to English": translate_text_bn_en,
43
- "Summarize": summarize_text,
44
- "Paraphrase": paraphrase_text
45
- }
46
- return task_funcs.get(task, lambda x: "Invalid Task")(text)
47
-
48
  # Task-specific examples
49
  examples_translate_en_bn = [
50
- ["The sky is blue, and the weather is nice."],
51
  ["Artificial intelligence is shaping the future."],
52
  ["Bangladesh is known for its rich culture and heritage."]
53
  ]
@@ -59,17 +49,15 @@ examples_translate_bn_en = [
59
  ]
60
 
61
  examples_summarize = [
62
- ["The Department of Computer Science and Engineering, established in 1982, was the first of its kind in Bangladesh. "
63
- "Attracting top students from all over the country, it offers both undergraduate and postgraduate degrees."],
64
- ["Climate change is one of the biggest challenges we face today. With rising temperatures and unpredictable weather, "
65
- "the world needs to come together to find sustainable solutions."],
66
- ["Technology has advanced rapidly over the past decade, with innovations in fields like AI, robotics, and quantum computing."]
67
  ]
68
 
69
  examples_paraphrase = [
70
- ["The cat is sitting on the mat."],
71
- ["He was very happy to receive the award."],
72
- ["The weather today is sunny and warm."]
73
  ]
74
 
75
  # Enhanced visual layout and interface design
@@ -78,39 +66,37 @@ with gr.Blocks() as demo:
78
  gr.Markdown("Explore the power of BanglaT5 with this easy-to-use interface for multiple tasks like translation, summarization, and paraphrasing.")
79
 
80
  with gr.Tabs():
 
81
  with gr.Tab("Translate English to Bengali"):
82
- gr.Examples(
83
- examples_translate_en_bn,
84
- inputs=gr.Textbox(label="Enter English Text", lines=5),
85
- outputs=gr.Textbox(label="Bengali Translation")
86
- )
87
-
 
88
  with gr.Tab("Translate Bengali to English"):
89
- gr.Examples(
90
- examples_translate_bn_en,
91
- inputs=gr.Textbox(label="Enter Bengali Text", lines=5),
92
- outputs=gr.Textbox(label="English Translation")
93
- )
94
-
 
95
  with gr.Tab("Summarize"):
96
- gr.Examples(
97
- examples_summarize,
98
- inputs=gr.Textbox(label="Enter Text to Summarize", lines=5),
99
- outputs=gr.Textbox(label="Summary")
100
- )
101
-
 
102
  with gr.Tab("Paraphrase"):
103
- gr.Examples(
104
- examples_paraphrase,
105
- inputs=gr.Textbox(label="Enter Text to Paraphrase", lines=5),
106
- outputs=gr.Textbox(label="Paraphrased Text")
107
- )
108
-
109
- input_text = gr.Textbox(label="Enter your text here", lines=5)
110
- task = gr.Dropdown(["Translate English to Bengali", "Translate Bengali to English", "Summarize", "Paraphrase"], label="Select Task")
111
- output_text = gr.Textbox(label="Output", lines=5)
112
-
113
- submit_btn = gr.Button("Run Task")
114
- submit_btn.click(process_text, inputs=[input_text, task], outputs=output_text)
115
 
116
  demo.launch()
 
 
35
  outputs = paraphrase_model.generate(**inputs)
36
  return paraphrase_tokenizer.decode(outputs[0], skip_special_tokens=True)
37
 
 
 
 
 
 
 
 
 
 
 
38
  # Task-specific examples
39
  examples_translate_en_bn = [
40
+ ["The Department of Computer Science and Engineering, the first department of its kind, was established in 1982 under the faculty of Electrical and Electronics Engineering. From the very initial days of its establishment, it has been able to attract the very best students of the country. Students securing topmost merit positions in the legendary admission test of BUET opt for studies in this department. At the very beginning, the department offered only M. Sc. Engg. and M Engg. degrees in Computer Science and Engineering. The Undergraduate program started in 1986. At first, 30 students were admitted each year for pursuing the B.Sc. Engineering degree."],
41
  ["Artificial intelligence is shaping the future."],
42
  ["Bangladesh is known for its rich culture and heritage."]
43
  ]
 
49
  ]
50
 
51
  examples_summarize = [
52
+ ["বাংলাদেশ দক্ষিণ এশিয়ার একটি সার্বভৌম রাষ্ট্র। বাংলাদেশের সাংবিধানিক নাম গণপ্রজাতন্ত্রী বাংলাদেশ। ভৌগোলিকভাবে বাংলাদেশের পশ্চিমে ভারতের পশ্চিমবঙ্গ, উত্তরে পশ্চিমবঙ্গ, আসাম ও মেঘালয়, পূর্ব সীমান্তে আসাম, ত্রিপুরা ও মিজোরাম, দক্ষিণ-পূর্ব সীমান্তে মিয়ানমারের চিন ও রাখাইন রাজ্য এবং দক্ষিণ উপকূলের দিকে বঙ্গোপসাগর অবস্থিত। ভৌগোলিকভাবে পৃথিবীর বৃহত্তম ব-দ্বীপের সিংহভাগ অঞ্চল জুড়ে বাংলাদেশ ভূখণ্ড অবস্থিত। জনসংখ্যার বিচারে প্রায় ১৭ কোটিরও অধিক জনসংখ্যা নিয়ে বাংলাদেশ বিশ্বের ৮ম বৃহত্তম দেশ। নদীমাতৃক বাংলাদেশ ভূখণ্ডের উপর দিয়ে বয়ে গেছে ৫৭টি আন্তর্জাতিক নদী। বাংলাদেশের উত্তর-পূর্বে ও দক্ষিণ-পূর্বে টারশিয়ারি যুগের পাহাড় ছেয়ে আছে। বিশ্বের বৃহত্তম ম্যানগ্রোভ অরণ্য সুন্দরবন ও দীর্ঘতম প্রাকৃতিক সৈকত কক্সবাজার সমুদ্র সৈকত বাংলাদেশে অবস্থিত।"],
53
+ ["বিশ্বের আরও একটি সেরা ক্লাব। স্প্যানিশ ফুটবলে বার্সেলোনারই প্রবল প্রতিদ্বন্দ্বী রিয়াল মাদ্রিদ। লিওনেল মেসির ক্লাব ইতিহাসে উয়েফা চ্যাম্পিয়নস লিগ জিতেছে মোট পাঁচবার। ইউরোপীয় কাপ উইনার্স কাপে তাদের সাফল্য আছে চারবার। পাশাপাশি তিনবার ক্লাব বিশ্বকাপ জেতা বার্সা লা লিগায় সাফল্য পেয়েছেন মোট ২৪ বার। ডিয়েগো ম্যারাডোনা, ইয়োহান ক্রুইফ, রিভালদোদের মতো খেলোয়াড়েরা এই ক্লাবের হয়ে ���ংশ হয়ে আছেন ইতিহাসের।"],
54
+ ["ফুল মানুষের হৃদয়কে উজ্জীবিত করে। বাংলাদেশের বিভিন্ন অঞ্চলে নানা রকমের ফুল ফুটে থাকে, যেমন গোলাপ, জবা, এবং কৃষ্ণকলি। বিশেষত বসন্তে, ফুলের সৌন্দর্য যেন চারপাশে ছড়িয়ে পড়ে, এবং এর গন্ধ বাতাসে ভাসে। ফুলের উৎসব, যেমন 'বসন্ত উৎসব', এ দেশের সংস্কৃতির একটি গুরুত্বপূর্ণ অংশ।"]
 
 
55
  ]
56
 
57
  examples_paraphrase = [
58
+ ["তিনজনের কেউই বাবার পথ ধরে প্রযুক্তি দুনিয়ায় হাঁটেননি।"],
59
+ ["প্রতিদিন নিয়মিত ব্যায়াম করা স্বাস্থ্যের জন্য উপকারী।"],
60
+ ["বাংলাদেশের প্রাকৃতিক সৌন্দর্য সকলকে মুগ্ধ করে।"]
61
  ]
62
 
63
  # Enhanced visual layout and interface design
 
66
  gr.Markdown("Explore the power of BanglaT5 with this easy-to-use interface for multiple tasks like translation, summarization, and paraphrasing.")
67
 
68
  with gr.Tabs():
69
+ # Tab for English to Bengali Translation
70
  with gr.Tab("Translate English to Bengali"):
71
+ en_bn_text = gr.Textbox(label="Enter English Text", lines=5)
72
+ en_bn_output = gr.Textbox(label="Bengali Translation")
73
+ gr.Examples(examples_translate_en_bn, inputs=en_bn_text)
74
+ en_bn_button = gr.Button("Run Task")
75
+ en_bn_button.click(translate_text_en_bn, inputs=en_bn_text, outputs=en_bn_output)
76
+
77
+ # Tab for Bengali to English Translation
78
  with gr.Tab("Translate Bengali to English"):
79
+ bn_en_text = gr.Textbox(label="Enter Bengali Text", lines=5)
80
+ bn_en_output = gr.Textbox(label="English Translation")
81
+ gr.Examples(examples_translate_bn_en, inputs=bn_en_text)
82
+ bn_en_button = gr.Button("Run Task")
83
+ bn_en_button.click(translate_text_bn_en, inputs=bn_en_text, outputs=bn_en_output)
84
+
85
+ # Tab for Summarization
86
  with gr.Tab("Summarize"):
87
+ summarize_text_input = gr.Textbox(label="Enter Text to Summarize", lines=5)
88
+ summarize_output = gr.Textbox(label="Summary")
89
+ gr.Examples(examples_summarize, inputs=summarize_text_input)
90
+ summarize_button = gr.Button("Run Task")
91
+ summarize_button.click(summarize_text, inputs=summarize_text_input, outputs=summarize_output)
92
+
93
+ # Tab for Paraphrasing
94
  with gr.Tab("Paraphrase"):
95
+ paraphrase_text_input = gr.Textbox(label="Enter Text to Paraphrase", lines=5)
96
+ paraphrase_output = gr.Textbox(label="Paraphrased Text")
97
+ gr.Examples(examples_paraphrase, inputs=paraphrase_text_input)
98
+ paraphrase_button = gr.Button("Run Task")
99
+ paraphrase_button.click(paraphrase_text, inputs=paraphrase_text_input, outputs=paraphrase_output)
 
 
 
 
 
 
 
100
 
101
  demo.launch()
102
+