anitalp commited on
Commit
8077007
Β·
verified Β·
1 Parent(s): b8904a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -19
app.py CHANGED
@@ -1,26 +1,27 @@
1
-
2
-
3
  import gradio as gr
4
 
5
- # 1. Define your title and description
6
- title = "Spanish Songs Toxicity Classification"
7
- description = "Pretrained models: ES-EN Translation (Opus MT) + Roberta Toxicity Classifier"
 
8
 
9
- # 2. Load the models using the modern gr.load syntax
10
- # Note: Adding "models/" prefix is the standard for the Hub
11
- translator_es = gr.load("models/Helsinki-NLP/opus-mt-es-en")
12
- toxicity_classifier = gr.load("models/SkolkovoInstitute/roberta_toxicity_classifier")
 
 
 
13
 
14
- # 3. Use gr.Series to chain them together
15
- # This passes the output of the translator directly into the classifier
16
- interface = gr.Series(
17
- translator_es,
18
- toxicity_classifier,
19
- description=description,
20
- title=title
21
  )
22
 
23
- # 4. Launch the app
24
  if __name__ == "__main__":
25
- interface.launch()
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()