zykrix commited on
Commit
73ff4b5
Β·
1 Parent(s): 1eb63ff

Added multi-tab layout and warning for summarization time

Browse files
Files changed (1) hide show
  1. app.py +85 -30
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
- # Main function that processes input
9
- def process_text(input_text):
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 summary, classification, events_formatted
17
 
18
- # Create the Gradio UI
19
  with gr.Blocks() as demo:
20
  gr.Markdown(
21
  """
22
  # 🧠 NLP Assistant
23
- Enter your text below and get:
24
- - πŸ“š **Summarization**
25
- - 🏷️ **Text Classification**
26
- - πŸ—‚οΈ **Event Detection**
27
  """
28
  )
29
 
30
- with gr.Row():
31
- input_text = gr.Textbox(
32
- label="Input Text",
33
- placeholder="Paste your article, document, or paragraph here...",
34
- lines=10
35
- )
36
-
37
- with gr.Row():
38
- submit_btn = gr.Button("Process")
39
-
40
- with gr.Row():
41
- summary_output = gr.Textbox(label="Summary", lines=5)
42
- classification_output = gr.Textbox(label="Classification", lines=2)
43
- events_output = gr.Textbox(label="Detected Events", lines=5)
44
-
45
- submit_btn.click(
46
- fn=process_text,
47
- inputs=[input_text],
48
- outputs=[summary_output, classification_output, events_output]
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__":