Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import signal
|
| 4 |
-
import asyncio
|
| 5 |
import warnings
|
| 6 |
import gradio as gr
|
| 7 |
import config
|
|
@@ -108,6 +107,13 @@ footer { visibility: hidden !important; }
|
|
| 108 |
fill: currentColor;
|
| 109 |
}
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
/* Mobile responsiveness */
|
| 112 |
@media (max-width: 768px) {
|
| 113 |
.dev-footer div {
|
|
@@ -118,6 +124,11 @@ footer { visibility: hidden !important; }
|
|
| 118 |
.dev-footer a {
|
| 119 |
margin: 5px 0;
|
| 120 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
}
|
| 122 |
"""
|
| 123 |
|
|
@@ -160,8 +171,6 @@ def create_ui():
|
|
| 160 |
|
| 161 |
# Get response
|
| 162 |
try:
|
| 163 |
-
# Note: chat_response doesn't typically check history in current logic,
|
| 164 |
-
# but if it did, we'd need to ensure it handles the new format or pass just strings.
|
| 165 |
response = chat_response(message, history)
|
| 166 |
except Exception as e:
|
| 167 |
response = f"Error: {str(e)}"
|
|
@@ -185,8 +194,34 @@ def create_ui():
|
|
| 185 |
|
| 186 |
return history, ""
|
| 187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
# Create the Gradio Blocks
|
| 189 |
-
with gr.Blocks(title="⚖️ LegalizeAI"
|
| 190 |
gr.Markdown(
|
| 191 |
"""
|
| 192 |
# ⚖️ LegalizeAI
|
|
@@ -201,8 +236,8 @@ def create_ui():
|
|
| 201 |
chatbot = gr.Chatbot(
|
| 202 |
height=500,
|
| 203 |
elem_id="chatbot",
|
| 204 |
-
avatar_images=(None, "⚖️")
|
| 205 |
-
show_copy_button
|
| 206 |
)
|
| 207 |
|
| 208 |
with gr.Row():
|
|
@@ -221,32 +256,6 @@ def create_ui():
|
|
| 221 |
clear_btn = gr.Button("Clear 🗑️", size="sm")
|
| 222 |
regenerate_btn = gr.Button("Regenerate 🔁", size="sm")
|
| 223 |
|
| 224 |
-
def regenerate_response(history):
|
| 225 |
-
"""Regenerate the last assistant response."""
|
| 226 |
-
if not history or len(history) < 2:
|
| 227 |
-
return history
|
| 228 |
-
|
| 229 |
-
# Get the last user message
|
| 230 |
-
last_user_msg = None
|
| 231 |
-
for msg in reversed(history):
|
| 232 |
-
if msg["role"] == "user":
|
| 233 |
-
last_user_msg = msg["content"]
|
| 234 |
-
break
|
| 235 |
-
|
| 236 |
-
if last_user_msg:
|
| 237 |
-
# Remove the last assistant response
|
| 238 |
-
if history[-1]["role"] == "assistant":
|
| 239 |
-
history.pop()
|
| 240 |
-
|
| 241 |
-
# Generate new response
|
| 242 |
-
try:
|
| 243 |
-
response = chat_response(last_user_msg, history)
|
| 244 |
-
history.append({"role": "assistant", "content": response})
|
| 245 |
-
except Exception as e:
|
| 246 |
-
history.append({"role": "assistant", "content": f"Error: {str(e)}"})
|
| 247 |
-
|
| 248 |
-
return history
|
| 249 |
-
|
| 250 |
# Example buttons logic
|
| 251 |
examples = [
|
| 252 |
"What is the punishment for theft in Pakistan?",
|
|
@@ -318,11 +327,12 @@ def main():
|
|
| 318 |
server_name=server_name,
|
| 319 |
server_port=7860,
|
| 320 |
share=False, # Don't use share=True on Spaces
|
| 321 |
-
favicon_path=
|
| 322 |
theme=theme,
|
| 323 |
show_error=True,
|
| 324 |
quiet=False,
|
| 325 |
-
show_api=False
|
|
|
|
| 326 |
)
|
| 327 |
|
| 328 |
except KeyboardInterrupt:
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import signal
|
|
|
|
| 4 |
import warnings
|
| 5 |
import gradio as gr
|
| 6 |
import config
|
|
|
|
| 107 |
fill: currentColor;
|
| 108 |
}
|
| 109 |
|
| 110 |
+
/* Chatbot styling */
|
| 111 |
+
#chatbot {
|
| 112 |
+
min-height: 500px;
|
| 113 |
+
max-height: 500px;
|
| 114 |
+
overflow-y: auto;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
/* Mobile responsiveness */
|
| 118 |
@media (max-width: 768px) {
|
| 119 |
.dev-footer div {
|
|
|
|
| 124 |
.dev-footer a {
|
| 125 |
margin: 5px 0;
|
| 126 |
}
|
| 127 |
+
|
| 128 |
+
#chatbot {
|
| 129 |
+
min-height: 400px;
|
| 130 |
+
max-height: 400px;
|
| 131 |
+
}
|
| 132 |
}
|
| 133 |
"""
|
| 134 |
|
|
|
|
| 171 |
|
| 172 |
# Get response
|
| 173 |
try:
|
|
|
|
|
|
|
| 174 |
response = chat_response(message, history)
|
| 175 |
except Exception as e:
|
| 176 |
response = f"Error: {str(e)}"
|
|
|
|
| 194 |
|
| 195 |
return history, ""
|
| 196 |
|
| 197 |
+
def regenerate_response(history):
|
| 198 |
+
"""Regenerate the last assistant response."""
|
| 199 |
+
if not history or len(history) < 2:
|
| 200 |
+
return history
|
| 201 |
+
|
| 202 |
+
# Get the last user message
|
| 203 |
+
last_user_msg = None
|
| 204 |
+
for msg in reversed(history):
|
| 205 |
+
if msg["role"] == "user":
|
| 206 |
+
last_user_msg = msg["content"]
|
| 207 |
+
break
|
| 208 |
+
|
| 209 |
+
if last_user_msg:
|
| 210 |
+
# Remove the last assistant response
|
| 211 |
+
if history[-1]["role"] == "assistant":
|
| 212 |
+
history.pop()
|
| 213 |
+
|
| 214 |
+
# Generate new response
|
| 215 |
+
try:
|
| 216 |
+
response = chat_response(last_user_msg, history)
|
| 217 |
+
history.append({"role": "assistant", "content": response})
|
| 218 |
+
except Exception as e:
|
| 219 |
+
history.append({"role": "assistant", "content": f"Error: {str(e)}"})
|
| 220 |
+
|
| 221 |
+
return history
|
| 222 |
+
|
| 223 |
# Create the Gradio Blocks
|
| 224 |
+
with gr.Blocks(title="⚖️ LegalizeAI") as demo:
|
| 225 |
gr.Markdown(
|
| 226 |
"""
|
| 227 |
# ⚖️ LegalizeAI
|
|
|
|
| 236 |
chatbot = gr.Chatbot(
|
| 237 |
height=500,
|
| 238 |
elem_id="chatbot",
|
| 239 |
+
avatar_images=(None, "⚖️")
|
| 240 |
+
# Removed show_copy_button for compatibility with older Gradio versions
|
| 241 |
)
|
| 242 |
|
| 243 |
with gr.Row():
|
|
|
|
| 256 |
clear_btn = gr.Button("Clear 🗑️", size="sm")
|
| 257 |
regenerate_btn = gr.Button("Regenerate 🔁", size="sm")
|
| 258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
# Example buttons logic
|
| 260 |
examples = [
|
| 261 |
"What is the punishment for theft in Pakistan?",
|
|
|
|
| 327 |
server_name=server_name,
|
| 328 |
server_port=7860,
|
| 329 |
share=False, # Don't use share=True on Spaces
|
| 330 |
+
favicon_path=None,
|
| 331 |
theme=theme,
|
| 332 |
show_error=True,
|
| 333 |
quiet=False,
|
| 334 |
+
show_api=False,
|
| 335 |
+
css=custom_css # CSS moved here for Gradio 6.0+ compatibility
|
| 336 |
)
|
| 337 |
|
| 338 |
except KeyboardInterrupt:
|