Daryl Lim Claude Opus 4.6 commited on
Commit
02f6bf9
·
1 Parent(s): 7a83d46

feat: replace gr.Interface with gr.Blocks for improved UI

Browse files

Two-column layout, Soft theme, searchable dropdown, copy button,
and example translations for a friendlier experience.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +43 -11
app.py CHANGED
@@ -68,17 +68,49 @@ def translate(text: str, target_language_name: str) -> str:
68
  def main() -> None:
69
  _, language_names = _build_language_mappings()
70
 
71
- demo = gr.Interface(
72
- fn=translate,
73
- inputs=[
74
- gr.Textbox(label="Text", placeholder="Enter text here"),
75
- gr.Dropdown(choices=language_names, value="French", label="Target language"),
76
- ],
77
- outputs=gr.Textbox(label="Translation"),
78
- title="MADLAD-400 Translation",
79
- description="Translation from English to evaluated languages (Table 14, Section A.9) from the "
80
- "[MADLAD-400 paper](https://arxiv.org/pdf/2309.04662) by Google DeepMind and Google Research.",
81
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  demo.launch()
84
 
 
68
  def main() -> None:
69
  _, language_names = _build_language_mappings()
70
 
71
+ with gr.Blocks(theme=gr.themes.Soft(), title="MADLAD-400 Translation") as demo:
72
+ gr.Markdown(
73
+ "# MADLAD-400 Translation\n"
74
+ "Translate English into 183 languages using Google's MADLAD-400 3B model. "
75
+ "[Paper](https://arxiv.org/pdf/2309.04662)"
76
+ )
77
+
78
+ target_language = gr.Dropdown(
79
+ choices=language_names,
80
+ value="French",
81
+ label="Target language",
82
+ )
83
+
84
+ with gr.Row():
85
+ input_text = gr.Textbox(
86
+ label="English",
87
+ placeholder="Enter English text here",
88
+ lines=4,
89
+ )
90
+ output_text = gr.Textbox(
91
+ label="Translation",
92
+ lines=4,
93
+ buttons=["copy"],
94
+ interactive=False,
95
+ )
96
+
97
+ translate_btn = gr.Button("Translate", variant="primary")
98
+
99
+ translate_btn.click(
100
+ fn=translate,
101
+ inputs=[input_text, target_language],
102
+ outputs=output_text,
103
+ )
104
+
105
+ gr.Examples(
106
+ examples=[
107
+ ["Hello, how are you today?", "French"],
108
+ ["The weather is beautiful.", "Japanese"],
109
+ ["Thank you very much.", "Swahili"],
110
+ ["Where is the train station?", "Hindi"],
111
+ ],
112
+ inputs=[input_text, target_language],
113
+ )
114
 
115
  demo.launch()
116