Spaces:
Runtime error
Runtime error
update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,37 @@
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
gr.inputs.Textbox(lines=15, placeholder="Enter text here"),
|
13 |
-
[gr.outputs.Textbox(lines=10, placeholder="Summarized text will appear here")],
|
14 |
-
title="Text Summarizer",
|
15 |
-
description="Summarizes text using the transformer library",
|
16 |
-
examples=[]
|
17 |
-
).launch()
|
|
|
1 |
+
#python3
|
2 |
+
#build a text summarizer using hugging face and gradio
|
3 |
+
|
4 |
+
|
5 |
import gradio as gr
|
6 |
import pandas as pd
|
7 |
+
import numpy as np
|
8 |
+
import tensorflow as tf
|
9 |
+
import transformers
|
10 |
+
from transformers import TFAutoModel, AutoTokenizer
|
11 |
+
|
12 |
+
model_class, tokenizer_class, pretrained_weights = (TFAutoModel, AutoTokenizer, 'bert-base-uncased')
|
13 |
+
|
14 |
+
# Load pretrained model/tokenizer
|
15 |
+
tokenizer = tokenizer_class.from_pretrained(pretrained_weights)
|
16 |
+
model = model_class.from_pretrained(pretrained_weights)
|
17 |
+
|
18 |
+
def get_summary(article):
|
19 |
+
article_input_ids = tokenizer.encode(article, return_tensors='tf')
|
20 |
+
summary_ids = model.generate(article_input_ids)
|
21 |
+
summary_txt = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
22 |
+
return summary_txt
|
23 |
|
24 |
+
def get_summary_gradio(article):
|
25 |
+
return get_summary(article)
|
26 |
|
27 |
+
iface = gr.Interface(get_summary_gradio, "textbox", "textbox", live=True,
|
28 |
+
examples=[
|
29 |
+
["The quick brown fox jumps over the lazy dog."],
|
30 |
+
["The world is a strange place. Sometimes, things are what they seem. But then, if you look closer, they can become something entirely different."],
|
31 |
+
["The sky is clear; the stars are twinkling. I'm going to bed now. Good night."],
|
32 |
+
["The president of the United States, and the president of the United Kingdom, have both been in the White House."],
|
33 |
+
["The president of the United States, and the president of the United Kingdom, have both been in the White House."]
|
34 |
+
])
|
35 |
|
36 |
+
if __name__ == "__main__":
|
37 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|