Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
|
|
3 |
|
4 |
# Loading translation model
|
5 |
-
|
6 |
-
|
7 |
|
8 |
# Loading summarization model
|
9 |
-
|
10 |
summarization_tokenizer = AutoTokenizer.from_pretrained("ieuniversity/sciencebrief_summarization")
|
11 |
summarization_model = AutoModelForSeq2SeqLM.from_pretrained("ieuniversity/sciencebrief_summarization")
|
12 |
|
13 |
-
|
14 |
-
|
15 |
#translation function
|
16 |
-
def
|
17 |
-
input_ids =
|
18 |
-
outputs =
|
19 |
-
decoded_output =
|
20 |
return decoded_output
|
21 |
|
22 |
#summarization function
|
23 |
-
def
|
24 |
input_ids = summarization_tokenizer.encode(text, return_tensors="pt")
|
25 |
output_ids = summarization_model.generate(input_ids)
|
26 |
summary = summarization_tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
@@ -32,10 +30,9 @@ summarization_output = gr.outputs.Textbox(label="Summarization Output")
|
|
32 |
translation_output = gr.outputs.Textbox(label="Translation Output")
|
33 |
|
34 |
gr.Interface(
|
35 |
-
fn=
|
36 |
inputs=input_text,
|
37 |
outputs=[summarization_output, translation_output],
|
38 |
-
layout="vertical",
|
39 |
title="Scientific Papers Text Summarization and Translation",
|
40 |
description="Enter some text and get a summary and translation in Spanish."
|
41 |
).launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
+
from gradio.mix import Parallel
|
4 |
|
5 |
# Loading translation model
|
6 |
+
translation_tokenizer = AutoTokenizer.from_pretrained("ieuniversity/sciencebrief_translation")
|
7 |
+
translation_model = AutoModelForSeq2SeqLM.from_pretrained("ieuniversity/sciencebrief_translation")
|
8 |
|
9 |
# Loading summarization model
|
|
|
10 |
summarization_tokenizer = AutoTokenizer.from_pretrained("ieuniversity/sciencebrief_summarization")
|
11 |
summarization_model = AutoModelForSeq2SeqLM.from_pretrained("ieuniversity/sciencebrief_summarization")
|
12 |
|
|
|
|
|
13 |
#translation function
|
14 |
+
def translate(text):
|
15 |
+
input_ids = translation_tokenizer.encode(text, return_tensors="pt")
|
16 |
+
outputs = translation_model.generate(input_ids)
|
17 |
+
decoded_output = translation_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
return decoded_output
|
19 |
|
20 |
#summarization function
|
21 |
+
def summarize(text):
|
22 |
input_ids = summarization_tokenizer.encode(text, return_tensors="pt")
|
23 |
output_ids = summarization_model.generate(input_ids)
|
24 |
summary = summarization_tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
|
|
30 |
translation_output = gr.outputs.Textbox(label="Translation Output")
|
31 |
|
32 |
gr.Interface(
|
33 |
+
fn=Parallel(summarize, translate),
|
34 |
inputs=input_text,
|
35 |
outputs=[summarization_output, translation_output],
|
|
|
36 |
title="Scientific Papers Text Summarization and Translation",
|
37 |
description="Enter some text and get a summary and translation in Spanish."
|
38 |
).launch()
|