Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,51 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
# Load the text summarization pipeline from Hugging Face Transformers
|
| 6 |
summarizer = pipeline("summarization")
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Interface for the Gradio app
|
| 13 |
iface = gr.Interface(
|
| 14 |
-
fn=
|
| 15 |
-
inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
|
| 16 |
outputs=gr.outputs.Textbox(label="Summary"),
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
# Launch the Gradio app
|
| 22 |
iface.launch()
|
| 23 |
-
|
| 24 |
-
iface.close()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import threading
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
# Load the text summarization pipeline from Hugging Face Transformers
|
| 6 |
summarizer = pipeline("summarization")
|
| 7 |
|
| 8 |
+
input_text = ""
|
| 9 |
+
summary = ""
|
| 10 |
+
running = False
|
| 11 |
+
lock = threading.Lock()
|
| 12 |
+
|
| 13 |
+
def summarize_text():
|
| 14 |
+
global input_text, summary, running
|
| 15 |
+
while running:
|
| 16 |
+
with lock:
|
| 17 |
+
if input_text.strip():
|
| 18 |
+
summary = summarizer(input_text, max_length=100, min_length=20, do_sample=False)[0]['summary_text']
|
| 19 |
+
|
| 20 |
+
# Start summarization in a separate thread
|
| 21 |
+
def start_summarization():
|
| 22 |
+
global running
|
| 23 |
+
running = True
|
| 24 |
+
thread = threading.Thread(target=summarize_text)
|
| 25 |
+
thread.start()
|
| 26 |
+
|
| 27 |
+
# Stop summarization
|
| 28 |
+
def stop_summarization():
|
| 29 |
+
global running
|
| 30 |
+
running = False
|
| 31 |
+
|
| 32 |
+
def update_input_text(new_input_text):
|
| 33 |
+
global input_text
|
| 34 |
+
input_text = new_input_text
|
| 35 |
+
|
| 36 |
+
def get_summary():
|
| 37 |
+
with lock:
|
| 38 |
+
return summary
|
| 39 |
|
| 40 |
# Interface for the Gradio app
|
| 41 |
iface = gr.Interface(
|
| 42 |
+
fn=get_summary,
|
| 43 |
+
inputs=[gr.inputs.Textbox(lines=5, label="Input Text"), gr.inputs.Button("Start", onclick=start_summarization), gr.inputs.Button("Stop", onclick=stop_summarization)],
|
| 44 |
outputs=gr.outputs.Textbox(label="Summary"),
|
| 45 |
+
live=True,
|
| 46 |
+
title="Interactive Text Summarizer",
|
| 47 |
+
description="Enter text, start the summarization, and stop it when you're satisfied.",
|
| 48 |
)
|
| 49 |
|
| 50 |
# Launch the Gradio app
|
| 51 |
iface.launch()
|
|
|
|
|
|