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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -65
app.py CHANGED
@@ -45,71 +45,72 @@ def process_text(text, task):
45
  }
46
  return task_funcs.get(task, lambda x: "Invalid Task")(text)
47
 
48
- # Task-specific examples with clear labels for each task
49
- examples = [
50
- ["Translate English to Bengali", [
51
- ["The sky is blue, and the weather is nice."],
52
- ["Artificial intelligence is shaping the future."],
53
- ["Bangladesh is known for its rich culture and heritage."]
54
- ]],
55
- ["Translate Bengali to English", [
56
- ["বাংলাদেশ দক্ষিণ এশিয়ার একটি সার্বভৌম রাষ্ট্র।"],
57
- ["ঢাকা বাংলাদেশের রাজধানী।"],
58
- ["রবীন্দ্রনাথ ঠাকুরের গান বাংলা সংস্কৃতির একটি অবিচ্ছেদ্য অংশ।"]
59
- ]],
60
- ["Summarize", [
61
- ["The Department of Computer Science and Engineering, established in 1982, was the first of its kind in Bangladesh. "
62
- "Attracting top students from all over the country, it offers both undergraduate and postgraduate degrees."],
63
- ["Climate change is one of the biggest challenges we face today. With rising temperatures and unpredictable weather, "
64
- "the world needs to come together to find sustainable solutions."],
65
- ["Technology has advanced rapidly over the past decade, with innovations in fields like AI, robotics, and quantum computing."]
66
- ]],
67
- ["Paraphrase", [
68
- ["The cat is sitting on the mat."],
69
- ["He was very happy to receive the award."],
70
- ["The weather today is sunny and warm."]
71
- ]]
 
72
  ]
73
 
74
  # Enhanced visual layout and interface design
75
- iface = gr.Interface(
76
- fn=process_text,
77
- inputs=[
78
- gr.Textbox(lines=5, label="Enter your text"),
79
- gr.Dropdown(
80
- ["Translate English to Bengali", "Translate Bengali to English", "Summarize", "Paraphrase"],
81
- label="Select Task",
82
- elem_id="dropdown-task",
83
- interactive=True
84
- )
85
- ],
86
- outputs=gr.Textbox(label="Output"),
87
- title="BanglaT5 Model Hub - Translation, Summarization & Paraphrasing",
88
- description="Explore the power of BanglaT5 with this easy-to-use interface for multiple tasks like translation, summarization, and paraphrasing.",
89
- theme="huggingface/space-shuttle",
90
- examples=examples, # Show examples as per tasks with 3 for each
91
- allow_flagging="auto",
92
- css="""
93
- #dropdown-task {
94
- color: #2C3E50;
95
- font-size: 18px;
96
- }
97
- .output-area {
98
- color: #2C3E50;
99
- }
100
- .examples {
101
- display: grid;
102
- grid-template-columns: 1fr 1fr;
103
- gap: 20px;
104
- }
105
- .output-text {
106
- background-color: #E8F6F3;
107
- }
108
- .gr-textbox {
109
- border-radius: 10px;
110
- }
111
- """
112
- )
113
-
114
- # Launch the Gradio app
115
- iface.launch(inline=False)
 
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
+ ]
54
+
55
+ examples_translate_bn_en = [
56
+ ["বাংলাদেশ দক্ষিণ এশিয়ার একটি সার্বভৌম রাষ্ট্র।"],
57
+ ["ঢাকা বাংলাদেশের রাজধানী।"],
58
+ ["রবীন্দ্রনাথ ঠাকুরের গান বাংলা সংস্কৃতির একটি অবিচ্ছেদ্য অংশ।"]
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
76
+ with gr.Blocks() as demo:
77
+ gr.Markdown("# BanglaT5 Model Hub - Translation, Summarization & Paraphrasing")
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()