Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,11 @@ import gradio as gr
|
|
| 2 |
import numpy as np
|
| 3 |
from pypdf import PdfReader
|
| 4 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def extract_text(file):
|
| 7 |
|
|
@@ -18,10 +23,18 @@ def extract_text(file):
|
|
| 18 |
text = ' '.join(text)
|
| 19 |
|
| 20 |
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
with gr.Blocks() as demo:
|
| 23 |
file_input = gr.File(label="Upload a PDF file")
|
| 24 |
text_output = gr.Textbox(label="Extracted Text")
|
|
|
|
| 25 |
file_input.upload(extract_text, inputs=file_input, outputs=text_output)
|
|
|
|
| 26 |
|
| 27 |
-
demo.launch()
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from pypdf import PdfReader
|
| 4 |
import os
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
|
| 7 |
+
model_path = "mrm8488/camembert2camembert_shared-finetuned-french-summarization"
|
| 8 |
+
pipe = pipeline('summarization', model_path)
|
| 9 |
+
min_length = 500
|
| 10 |
|
| 11 |
def extract_text(file):
|
| 12 |
|
|
|
|
| 23 |
text = ' '.join(text)
|
| 24 |
|
| 25 |
return text
|
| 26 |
+
|
| 27 |
+
def summarise(text):
|
| 28 |
+
|
| 29 |
+
pred = pipe(text , min_length)
|
| 30 |
+
|
| 31 |
+
return pred[0]["summary_text"]
|
| 32 |
|
| 33 |
with gr.Blocks() as demo:
|
| 34 |
file_input = gr.File(label="Upload a PDF file")
|
| 35 |
text_output = gr.Textbox(label="Extracted Text")
|
| 36 |
+
summary_output = gr.Textbox(label="Summary")
|
| 37 |
file_input.upload(extract_text, inputs=file_input, outputs=text_output)
|
| 38 |
+
text_output.change(summarise,text_output,summary_output)
|
| 39 |
|
| 40 |
+
demo.launch()
|