TNK21 commited on
Commit
c1f91ca
·
1 Parent(s): e6cf48c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -37
app.py CHANGED
@@ -1,50 +1,21 @@
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
 
1
  import gradio as gr
2
+ import tensorflow
3
  from transformers import pipeline
4
 
5
  # Load the text summarization pipeline from Hugging Face Transformers
6
  summarizer = pipeline("summarization")
7
 
8
+ def summarize_text(input_text):
9
+ summary = summarizer(input_text, max_length=100, min_length=20, do_sample=False)[0]['summary_text']
10
+ return summary
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  # Interface for the Gradio app
13
  iface = gr.Interface(
14
+ fn=summarize_text,
15
+ inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
16
  outputs=gr.outputs.Textbox(label="Summary"),
17
+ title="Text Summarizer",
18
+ description="Enter a piece of text, and the app will provide a summary.",
 
19
  )
20
 
21
  # Launch the Gradio app