Spaces:
Running
Running
Daryl Lim Claude Opus 4.6 commited on
Commit ·
c31dbc6
1
Parent(s): 63c966a
feat: add preview table to batch tab UI
Browse filesAdd gr.Dataframe component to the Batch tab so translate_batch() results
display as a preview table alongside the downloadable file.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- app.py +4 -2
- tests/test_app.py +16 -0
app.py
CHANGED
|
@@ -231,14 +231,16 @@ def _build_demo() -> gr.Blocks:
|
|
| 231 |
with gr.Tab("Batch"):
|
| 232 |
gr.Markdown("Upload a `.txt` file (one sentence per line) or a `.csv` file with a `text` column.")
|
| 233 |
batch_input = gr.File(label="Upload file", file_types=[".txt", ".csv"])
|
| 234 |
-
batch_output = gr.File(label="Download translations", interactive=False)
|
| 235 |
|
| 236 |
batch_btn = gr.Button("Translate", variant="primary")
|
| 237 |
|
|
|
|
|
|
|
|
|
|
| 238 |
batch_btn.click(
|
| 239 |
fn=translate_batch,
|
| 240 |
inputs=[batch_input, target_language, max_new_tokens, num_beams, temperature],
|
| 241 |
-
outputs=batch_output,
|
| 242 |
)
|
| 243 |
|
| 244 |
return demo
|
|
|
|
| 231 |
with gr.Tab("Batch"):
|
| 232 |
gr.Markdown("Upload a `.txt` file (one sentence per line) or a `.csv` file with a `text` column.")
|
| 233 |
batch_input = gr.File(label="Upload file", file_types=[".txt", ".csv"])
|
|
|
|
| 234 |
|
| 235 |
batch_btn = gr.Button("Translate", variant="primary")
|
| 236 |
|
| 237 |
+
batch_preview = gr.Dataframe(label="Preview", interactive=False)
|
| 238 |
+
batch_output = gr.File(label="Download translations", interactive=False)
|
| 239 |
+
|
| 240 |
batch_btn.click(
|
| 241 |
fn=translate_batch,
|
| 242 |
inputs=[batch_input, target_language, max_new_tokens, num_beams, temperature],
|
| 243 |
+
outputs=[batch_preview, batch_output],
|
| 244 |
)
|
| 245 |
|
| 246 |
return demo
|
tests/test_app.py
CHANGED
|
@@ -313,6 +313,22 @@ def test_build_table_data_csv():
|
|
| 313 |
assert result["data"] == [["1", "Hello", "Bonjour"]]
|
| 314 |
|
| 315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
# --- UI component tests ---
|
| 317 |
|
| 318 |
|
|
|
|
| 313 |
assert result["data"] == [["1", "Hello", "Bonjour"]]
|
| 314 |
|
| 315 |
|
| 316 |
+
# --- Batch tab Dataframe tests ---
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def test_demo_has_dataframe_component(demo):
|
| 320 |
+
"""Batch tab should contain a Dataframe component for preview."""
|
| 321 |
+
dataframes = [b for b in demo.blocks.values() if type(b).__name__ == "Dataframe"]
|
| 322 |
+
assert len(dataframes) >= 1, "Expected at least one Dataframe component"
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def test_dataframe_is_non_interactive(demo):
|
| 326 |
+
"""Batch preview Dataframe should be non-interactive."""
|
| 327 |
+
dataframes = [b for b in demo.blocks.values() if type(b).__name__ == "Dataframe"]
|
| 328 |
+
assert len(dataframes) >= 1
|
| 329 |
+
assert dataframes[0].interactive is False
|
| 330 |
+
|
| 331 |
+
|
| 332 |
# --- UI component tests ---
|
| 333 |
|
| 334 |
|