Spaces:
Sleeping
Sleeping
app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,25 @@
|
|
1 |
import torch
|
2 |
import gradio as gr
|
|
|
3 |
from transformers import pipeline
|
4 |
|
5 |
# Initialize the summarization pipeline
|
6 |
pipe = pipeline("summarization", model="Falconsai/text_summarization")
|
7 |
|
8 |
-
# Store chat history as a list of tuples [(user_input, summary), ...]
|
9 |
-
chat_history = []
|
10 |
-
|
11 |
# Define the summarize function
|
12 |
-
def summarize(
|
13 |
-
|
14 |
-
|
15 |
-
# Clear history if requested
|
16 |
-
if clear_history:
|
17 |
-
chat_history = []
|
18 |
-
return chat_history
|
19 |
-
|
20 |
-
# Generate the summary
|
21 |
-
output = pipe(input_text)
|
22 |
-
summary = output[0]['summary_text']
|
23 |
-
|
24 |
-
# Append the user's input and the summary to chat history
|
25 |
-
chat_history.append(("User", input_text))
|
26 |
-
chat_history.append(("Summarizer", summary))
|
27 |
-
|
28 |
-
# Return the updated chat history
|
29 |
-
return chat_history
|
30 |
|
31 |
# Define the Gradio interface
|
32 |
-
|
33 |
-
|
34 |
-
gr.
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
input_text = gr.Textbox(lines=10, placeholder="Enter text to summarize here...", label="Input Text")
|
40 |
-
clear_history_btn = gr.Button("Clear History")
|
41 |
-
|
42 |
-
# Chatbot-style output
|
43 |
-
chatbot = gr.Chatbot(label="History", type="messages")
|
44 |
-
|
45 |
-
# Submit button for summarization
|
46 |
-
submit_button = gr.Button("Summarize")
|
47 |
-
|
48 |
-
# Functionality for buttons
|
49 |
-
submit_button.click(summarize, inputs=[input_text, gr.State(False)], outputs=chatbot)
|
50 |
-
clear_history_btn.click(summarize, inputs=["", gr.State(True)], outputs=chatbot)
|
51 |
|
52 |
# Launch the interface
|
53 |
if __name__ == "__main__":
|
54 |
-
|
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
+
# Use a pipeline as a high-level helper
|
4 |
from transformers import pipeline
|
5 |
|
6 |
# Initialize the summarization pipeline
|
7 |
pipe = pipeline("summarization", model="Falconsai/text_summarization")
|
8 |
|
|
|
|
|
|
|
9 |
# Define the summarize function
|
10 |
+
def summarize(input):
|
11 |
+
output = pipe(input)
|
12 |
+
return output[0]['summary_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Define the Gradio interface
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=summarize,
|
17 |
+
inputs=gr.Textbox(lines=12, placeholder="Enter text to summarize here..."),
|
18 |
+
outputs="text",
|
19 |
+
title="Text Summarizer",
|
20 |
+
description="Enter a long piece of text, and the summarizer will provide a concise summary."
|
21 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Launch the interface
|
24 |
if __name__ == "__main__":
|
25 |
+
iface.launch()
|