astrojuanlu commited on
Commit
81ddc22
·
1 Parent(s): cac43d6

Rework for summarization application

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -1,7 +1,19 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  iface.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
 
 
4
 
5
+ def summarize(post):
6
+ detector = pipeline(
7
+ "text-classification", model="papluca/xlm-roberta-base-language-detection"
8
+ )
9
+ lang_results = detector(post)
10
+ if (detected_lang := lang_results[0]["label"]) == "en":
11
+ summarizer_model_name = "papluca/xlm-roberta-base-language-detection"
12
+ elif detected_lang == "es":
13
+ summarizer_model_name = "ELiRF/mbart-large-cc25-dacsa-es"
14
+ pipe = pipeline("summarization", model=summarizer_model_name)
15
+ return pipe(post)[0]["summary_text"]
16
+
17
+
18
+ iface = gr.Interface(fn=summarize, inputs="text", outputs="text")
19
  iface.launch()