Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -509,8 +509,14 @@ def translate_dataset(train_url, local_parquet_path, input_file_path, output_fil
|
|
| 509 |
logging.error(f"Failed to upload {output_file_path} to Hugging Face: {e}")
|
| 510 |
|
| 511 |
# Setup logging configuration
|
| 512 |
-
|
| 513 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
|
| 515 |
# Main function to handle the translation workflow
|
| 516 |
def main(dataset_url, model_type, output_dataset_name, range_specification, token: gr.OAuthToken | None, profile: gr.OAuthProfile | None):
|
|
@@ -570,15 +576,15 @@ def main(dataset_url, model_type, output_dataset_name, range_specification, toke
|
|
| 570 |
return "Login failed. Please try again."
|
| 571 |
except Exception as e:
|
| 572 |
logging.error(f"An error occurred in the main function: {e}")
|
| 573 |
-
return f"An error occurred: {e}"
|
| 574 |
|
| 575 |
# Gradio interface setup
|
| 576 |
gradio_title = "🧐 WMT21 Dataset Translation"
|
| 577 |
gradio_desc = """This tool translates datasets using the WMT21 translation model.
|
| 578 |
## 💭 What Does This Tool Do:
|
| 579 |
- Translates datasets based on the selected model type.
|
| 580 |
-
- Uploads the translated dataset to Hugging Face.
|
| 581 |
-
## 📊 Dataset Types:
|
| 582 |
- **mix**:
|
| 583 |
- `prompt`: List of dictionaries with 'content' and 'role' fields (multi-turn conversation).
|
| 584 |
- `chosen`: Single dictionary with 'content' and 'role' fields.
|
|
@@ -592,8 +598,8 @@ gradio_desc = """This tool translates datasets using the WMT21 translation model
|
|
| 592 |
- `chosen`: List of dictionaries with 'content' and 'role' fields.
|
| 593 |
- `rejected`: List of dictionaries with 'content' and 'role' fields.
|
| 594 |
## 🛠️ Backend:
|
| 595 |
-
The translation backend runs on the Hugging Face Hub API.
|
| 596 |
-
|
| 597 |
# Define the theme
|
| 598 |
theme = gr.themes.Soft(text_size="lg", spacing_size="lg")
|
| 599 |
|
|
@@ -620,6 +626,6 @@ with gr.Blocks(theme=theme) as demo:
|
|
| 620 |
submit_btn = gr.Button("Translate Dataset", variant="primary")
|
| 621 |
submit_btn.click(main, inputs=[dataset_url, model_type, output_dataset_name, range_specification], outputs=output)
|
| 622 |
|
| 623 |
-
gr.Markdown(
|
| 624 |
|
| 625 |
demo.launch(share=True)
|
|
|
|
| 509 |
logging.error(f"Failed to upload {output_file_path} to Hugging Face: {e}")
|
| 510 |
|
| 511 |
# Setup logging configuration
|
| 512 |
+
log_stream = io.StringIO()
|
| 513 |
+
logging.basicConfig(level=logging.INFO,
|
| 514 |
+
format='%(asctime)s - %(levelname)s - %(message)s',
|
| 515 |
+
handlers=[
|
| 516 |
+
logging.FileHandler("translation.log", mode='a'),
|
| 517 |
+
logging.StreamHandler(log_stream)
|
| 518 |
+
])
|
| 519 |
+
logger = logging.getLogger(__name__)
|
| 520 |
|
| 521 |
# Main function to handle the translation workflow
|
| 522 |
def main(dataset_url, model_type, output_dataset_name, range_specification, token: gr.OAuthToken | None, profile: gr.OAuthProfile | None):
|
|
|
|
| 576 |
return "Login failed. Please try again."
|
| 577 |
except Exception as e:
|
| 578 |
logging.error(f"An error occurred in the main function: {e}")
|
| 579 |
+
return f"An error occurred: {e}\n\n### Logs:\n{log_stream.getvalue()}"
|
| 580 |
|
| 581 |
# Gradio interface setup
|
| 582 |
gradio_title = "🧐 WMT21 Dataset Translation"
|
| 583 |
gradio_desc = """This tool translates datasets using the WMT21 translation model.
|
| 584 |
## 💭 What Does This Tool Do:
|
| 585 |
- Translates datasets based on the selected model type.
|
| 586 |
+
- Uploads the translated dataset to Hugging Face."""
|
| 587 |
+
datasets_desc = """## 📊 Dataset Types:
|
| 588 |
- **mix**:
|
| 589 |
- `prompt`: List of dictionaries with 'content' and 'role' fields (multi-turn conversation).
|
| 590 |
- `chosen`: Single dictionary with 'content' and 'role' fields.
|
|
|
|
| 598 |
- `chosen`: List of dictionaries with 'content' and 'role' fields.
|
| 599 |
- `rejected`: List of dictionaries with 'content' and 'role' fields.
|
| 600 |
## 🛠️ Backend:
|
| 601 |
+
The translation backend runs on the Hugging Face Hub API."""
|
| 602 |
+
|
| 603 |
# Define the theme
|
| 604 |
theme = gr.themes.Soft(text_size="lg", spacing_size="lg")
|
| 605 |
|
|
|
|
| 626 |
submit_btn = gr.Button("Translate Dataset", variant="primary")
|
| 627 |
submit_btn.click(main, inputs=[dataset_url, model_type, output_dataset_name, range_specification], outputs=output)
|
| 628 |
|
| 629 |
+
gr.Markdown(datasets_desc)
|
| 630 |
|
| 631 |
demo.launch(share=True)
|