Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,27 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
# 1.
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
# 2.
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
# 3.
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
)
|
| 22 |
|
| 23 |
-
# 4. Launch
|
| 24 |
if __name__ == "__main__":
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# 1. Load the models using the Inference API
|
| 4 |
+
# We use gr.load to get the 'functions' for these models
|
| 5 |
+
translator = gr.load("models/Helsinki-NLP/opus-mt-es-en")
|
| 6 |
+
classifier = gr.load("models/SkolkovoInstitute/roberta_toxicity_classifier")
|
| 7 |
|
| 8 |
+
# 2. Define a wrapper function to chain them
|
| 9 |
+
def Spanish_Toxicity_Check(text):
|
| 10 |
+
# Step 1: Translate Spanish to English
|
| 11 |
+
english_text = translator(text)
|
| 12 |
+
# Step 2: Pass English result to Toxicity classifier
|
| 13 |
+
results = classifier(english_text)
|
| 14 |
+
return results
|
| 15 |
|
| 16 |
+
# 3. Create the Interface
|
| 17 |
+
demo = gr.Interface(
|
| 18 |
+
fn=Spanish_Toxicity_Check,
|
| 19 |
+
inputs=gr.Textbox(label="Input Spanish Song Lyric", placeholder="Escribe aquΓ..."),
|
| 20 |
+
outputs=gr.Label(label="Toxicity Analysis"),
|
| 21 |
+
title="Spanish Songs Toxicity Classification",
|
| 22 |
+
description="Pretrained models: ES-EN Translation (Opus MT) + Roberta Toxicity Classifier"
|
| 23 |
)
|
| 24 |
|
| 25 |
+
# 4. Launch
|
| 26 |
if __name__ == "__main__":
|
| 27 |
+
demo.launch()
|
|
|