Spaces:
Sleeping
Sleeping
zykrix commited on
Commit Β·
73ff4b5
1
Parent(s): 1eb63ff
Added multi-tab layout and warning for summarization time
Browse files
app.py
CHANGED
|
@@ -5,48 +5,103 @@ from modules.summarizer import summarize_text
|
|
| 5 |
from modules.classifier import classify_text
|
| 6 |
from modules.event_detector import detect_events
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
def
|
| 10 |
summary = summarize_text(input_text)
|
|
|
|
|
|
|
|
|
|
| 11 |
classification = classify_text(input_text)
|
|
|
|
|
|
|
|
|
|
| 12 |
events = detect_events(input_text)
|
| 13 |
-
|
| 14 |
-
# Display events in a comma-separated format
|
| 15 |
events_formatted = ', '.join(events) if isinstance(events, list) else events
|
| 16 |
-
return
|
| 17 |
|
| 18 |
-
# Create
|
| 19 |
with gr.Blocks() as demo:
|
| 20 |
gr.Markdown(
|
| 21 |
"""
|
| 22 |
# π§ NLP Assistant
|
| 23 |
-
|
| 24 |
-
- π
|
| 25 |
-
- π·οΈ
|
| 26 |
-
- ποΈ
|
| 27 |
"""
|
| 28 |
)
|
| 29 |
|
| 30 |
-
with gr.
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# Launch Gradio app
|
| 52 |
if __name__ == "__main__":
|
|
|
|
| 5 |
from modules.classifier import classify_text
|
| 6 |
from modules.event_detector import detect_events
|
| 7 |
|
| 8 |
+
# Define individual task functions
|
| 9 |
+
def process_summarization(input_text):
|
| 10 |
summary = summarize_text(input_text)
|
| 11 |
+
return summary
|
| 12 |
+
|
| 13 |
+
def process_classification(input_text):
|
| 14 |
classification = classify_text(input_text)
|
| 15 |
+
return classification
|
| 16 |
+
|
| 17 |
+
def process_event_detection(input_text):
|
| 18 |
events = detect_events(input_text)
|
|
|
|
|
|
|
| 19 |
events_formatted = ', '.join(events) if isinstance(events, list) else events
|
| 20 |
+
return events_formatted
|
| 21 |
|
| 22 |
+
# Create Gradio UI with Tabs
|
| 23 |
with gr.Blocks() as demo:
|
| 24 |
gr.Markdown(
|
| 25 |
"""
|
| 26 |
# π§ NLP Assistant
|
| 27 |
+
A simple app for:
|
| 28 |
+
- π Summarization
|
| 29 |
+
- π·οΈ News Classification
|
| 30 |
+
- ποΈ Event Detection
|
| 31 |
"""
|
| 32 |
)
|
| 33 |
|
| 34 |
+
with gr.Tabs():
|
| 35 |
+
# Summarization Tab
|
| 36 |
+
with gr.Tab("π Summarization"):
|
| 37 |
+
gr.Markdown(
|
| 38 |
+
"""
|
| 39 |
+
## π Summarization
|
| 40 |
+
Enter your text below and get a summarized version.
|
| 41 |
+
|
| 42 |
+
β οΈ **Note:**
|
| 43 |
+
- This task can take **~800β1000 seconds (~13β16 minutes)** for about **700β800 words**.
|
| 44 |
+
- Longer articles will take **even more time**.
|
| 45 |
+
- Please be patient!
|
| 46 |
+
"""
|
| 47 |
+
)
|
| 48 |
+
input_text_sum = gr.Textbox(
|
| 49 |
+
label="Input Text for Summarization",
|
| 50 |
+
placeholder="Paste your article, document, or paragraph here...",
|
| 51 |
+
lines=10
|
| 52 |
+
)
|
| 53 |
+
summarize_btn = gr.Button("Summarize")
|
| 54 |
+
summary_output = gr.Textbox(label="Summary", lines=8)
|
| 55 |
+
|
| 56 |
+
summarize_btn.click(
|
| 57 |
+
fn=process_summarization,
|
| 58 |
+
inputs=[input_text_sum],
|
| 59 |
+
outputs=[summary_output]
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# Classification Tab
|
| 63 |
+
with gr.Tab("π·οΈ Classification"):
|
| 64 |
+
gr.Markdown(
|
| 65 |
+
"""
|
| 66 |
+
## π·οΈ News/Text Classification
|
| 67 |
+
Enter your text below to detect its category.
|
| 68 |
+
"""
|
| 69 |
+
)
|
| 70 |
+
input_text_classify = gr.Textbox(
|
| 71 |
+
label="Input Text for Classification",
|
| 72 |
+
placeholder="Paste your article or paragraph here...",
|
| 73 |
+
lines=10
|
| 74 |
+
)
|
| 75 |
+
classify_btn = gr.Button("Classify")
|
| 76 |
+
classification_output = gr.Textbox(label="Classification Result", lines=2)
|
| 77 |
+
|
| 78 |
+
classify_btn.click(
|
| 79 |
+
fn=process_classification,
|
| 80 |
+
inputs=[input_text_classify],
|
| 81 |
+
outputs=[classification_output]
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
# Event Detection Tab
|
| 85 |
+
with gr.Tab("ποΈ Event Detection"):
|
| 86 |
+
gr.Markdown(
|
| 87 |
+
"""
|
| 88 |
+
## ποΈ Event Detection
|
| 89 |
+
Extract keywords and named entities from your text.
|
| 90 |
+
"""
|
| 91 |
+
)
|
| 92 |
+
input_text_events = gr.Textbox(
|
| 93 |
+
label="Input Text for Event Detection",
|
| 94 |
+
placeholder="Paste your article, news, or report here...",
|
| 95 |
+
lines=10
|
| 96 |
+
)
|
| 97 |
+
detect_btn = gr.Button("Detect Events")
|
| 98 |
+
events_output = gr.Textbox(label="Detected Events", lines=8)
|
| 99 |
+
|
| 100 |
+
detect_btn.click(
|
| 101 |
+
fn=process_event_detection,
|
| 102 |
+
inputs=[input_text_events],
|
| 103 |
+
outputs=[events_output]
|
| 104 |
+
)
|
| 105 |
|
| 106 |
# Launch Gradio app
|
| 107 |
if __name__ == "__main__":
|