Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 + [
|
|
|
|
|
|
|
| 22 |
return history, history
|
| 23 |
|
| 24 |
if len(user_input.split()) < 30:
|
| 25 |
-
history = history + [
|
| 26 |
-
"
|
| 27 |
-
"
|
| 28 |
-
|
| 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
|
| 73 |
-
history = history + [
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
except Exception as e:
|
| 76 |
-
history = history + [
|
|
|
|
|
|
|
|
|
|
| 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:
|
| 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(
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
| 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)
|
|
|
|
| 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)
|