Spaces:
Runtime error
Runtime error
change to summarize
Browse files
app.py
CHANGED
|
@@ -1,5 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import wikipedia
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def greet(name):
|
| 5 |
return "Hello " + name.orig_name + "!!"
|
|
@@ -19,8 +36,11 @@ def get_wiki(search_term):
|
|
| 19 |
|
| 20 |
def inference(file):
|
| 21 |
get_ocr()
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
-
iface = gr.Interface(fn=
|
| 26 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import wikipedia
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
## Setting to use the 0th GPU
|
| 7 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
| 8 |
+
|
| 9 |
+
def summarize(text):
|
| 10 |
+
## Setting to use the bart-large-cnn model for summarization
|
| 11 |
+
summarizer = pipeline("summarization")
|
| 12 |
+
|
| 13 |
+
## To use the t5-base model for summarization:
|
| 14 |
+
## summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base", framework="tf")
|
| 15 |
+
|
| 16 |
+
summary_text = summarizer(text, max_length=100, min_length=5, do_sample=False)[0]['summary_text']
|
| 17 |
+
print(f'Length of initial text: {len(text)}')
|
| 18 |
+
print(f'Length of summary: {len(summary_text)}')
|
| 19 |
+
print(summary_text)
|
| 20 |
|
| 21 |
def greet(name):
|
| 22 |
return "Hello " + name.orig_name + "!!"
|
|
|
|
| 36 |
|
| 37 |
def inference(file):
|
| 38 |
get_ocr()
|
| 39 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("sgugger/my-awesome-model")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
+
iface = gr.Interface(fn=summarize, inputs="text", outputs="text")
|
| 46 |
iface.launch()
|