rajeshree2 commited on
Commit
646d51e
Β·
verified Β·
1 Parent(s): 1ee1332

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -18,15 +18,20 @@ def summarize_text(user_input, history, max_len, min_len, bullet_mode):
18
  user_input = user_input.strip()
19
 
20
  if not user_input:
21
- history = history + [("", "⚠️ Please enter some text to summarize.")]
 
 
22
  return history, history
23
 
24
  if len(user_input.split()) < 30:
25
- history = history + [(user_input,
26
- "πŸ‘‹ Hello! I'm your Text Summarizer.\n\n"
27
- "Paste any long article or document (30+ words) and I'll summarize it.\n\n"
28
- "Use the settings on the right to adjust length and format."
29
- )]
 
 
 
30
  return history, history
31
 
32
  try:
@@ -69,11 +74,17 @@ def summarize_text(user_input, history, max_len, min_len, bullet_mode):
69
  f"Reduced by {reduction}%"
70
  )
71
 
72
- label = user_input[:80] + "..." if len(user_input) > 80 else user_input
73
- history = history + [(label, out)]
 
 
 
74
 
75
  except Exception as e:
76
- history = history + [(user_input[:60] + "...", f"❌ Error: {str(e)}")]
 
 
 
77
 
78
  return history, history
79
 
@@ -83,7 +94,7 @@ def clear_chat():
83
 
84
 
85
  # ── 3. Gradio UI ───────────────────────────────────────────────────
86
- with gr.Blocks(title="Text Summarizer") as demo: # βœ… NO theme here
87
 
88
  gr.Markdown("""
89
  # πŸ“ Text Summarization Chatbox
@@ -94,8 +105,11 @@ with gr.Blocks(title="Text Summarizer") as demo: # βœ… NO theme here
94
  with gr.Row():
95
 
96
  with gr.Column(scale=7):
97
- chatbot = gr.Chatbot(height=450) # βœ… No type, no bubble_full_width
98
- state = gr.State([])
 
 
 
99
 
100
  with gr.Row():
101
  txt_input = gr.Textbox(
@@ -148,4 +162,4 @@ with gr.Blocks(title="Text Summarizer") as demo: # βœ… NO theme here
148
  clear_btn.click(clear_chat, outputs=[chatbot, state])
149
 
150
  # ── 4. Launch ──────────────────────────────────────────────────────
151
- demo.launch(server_name="0.0.0.0", server_port=7860) # βœ… theme removed completely
 
18
  user_input = user_input.strip()
19
 
20
  if not user_input:
21
+ history = history + [
22
+ {"role": "assistant", "content": "⚠️ Please enter some text to summarize."}
23
+ ]
24
  return history, history
25
 
26
  if len(user_input.split()) < 30:
27
+ history = history + [
28
+ {"role": "user", "content": user_input},
29
+ {"role": "assistant", "content": (
30
+ "πŸ‘‹ Hello! I'm your Text Summarizer.\n\n"
31
+ "Paste any long article or document (30+ words) and I'll summarize it.\n\n"
32
+ "Use the settings below to adjust length and format."
33
+ )}
34
+ ]
35
  return history, history
36
 
37
  try:
 
74
  f"Reduced by {reduction}%"
75
  )
76
 
77
+ label = user_input[:80] + "..." if len(user_input) > 80 else user_input
78
+ history = history + [
79
+ {"role": "user", "content": label},
80
+ {"role": "assistant", "content": out}
81
+ ]
82
 
83
  except Exception as e:
84
+ history = history + [
85
+ {"role": "user", "content": user_input[:60] + "..."},
86
+ {"role": "assistant", "content": f"❌ Error: {str(e)}"}
87
+ ]
88
 
89
  return history, history
90
 
 
94
 
95
 
96
  # ── 3. Gradio UI ───────────────────────────────────────────────────
97
+ with gr.Blocks(title="Text Summarizer") as demo:
98
 
99
  gr.Markdown("""
100
  # πŸ“ Text Summarization Chatbox
 
105
  with gr.Row():
106
 
107
  with gr.Column(scale=7):
108
+ chatbot = gr.Chatbot(
109
+ height=450,
110
+ type="messages" # βœ… matches dict format in function
111
+ )
112
+ state = gr.State([])
113
 
114
  with gr.Row():
115
  txt_input = gr.Textbox(
 
162
  clear_btn.click(clear_chat, outputs=[chatbot, state])
163
 
164
  # ── 4. Launch ──────────────────────────────────────────────────────
165
+ demo.launch(server_name="0.0.0.0", server_port=7860)