Spaces:
Sleeping
Sleeping
File size: 2,147 Bytes
5afd6d6 e501a79 a7e57a7 3d2519f 474fc65 8047a9d e501a79 5afd6d6 e501a79 a7e57a7 2ef1847 e501a79 2ef1847 5afd6d6 91ba198 5afd6d6 e501a79 5afd6d6 e501a79 5afd6d6 e501a79 5afd6d6 e501a79 5afd6d6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | # app.py — Gradio ChatInterface (4.31-safe, no deprecated tuples warning)
# - No Blocks wrapper (avoids DuplicateBlockError)
# - Pass our own Chatbot to ChatInterface so it doesn't create a tuples-based default
# - Auto-uses type="messages" on >= 4.37; legacy on 4.31 without errors
# - Mobile CSS: fixed height + scroll + wrapping
# - Version-safe queue() and launch()
import gradio as gr
from bot_inference import chatbot_reply
def respond(message, history):
# history is ignored by your bot; keep signature compatible with ChatInterface
return chatbot_reply(message)
def _supports_messages(ver: str) -> bool:
try:
parts = [int(p) for p in ver.split(".")[:3]]
parts += [0] * (3 - len(parts))
return tuple(parts) >= (4, 37, 0)
except Exception:
return False
# Prepare Chatbot to pass into ChatInterface (not inside Blocks)
chatbot_kwargs = dict(height=540, show_copy_button=True, elem_id="chatbox")
if _supports_messages(gr.__version__):
chatbot_kwargs["type"] = "messages"
chat = gr.Chatbot(**chatbot_kwargs)
MOBILE_CSS = """
/* ====== MOBILE-SAFE CHAT STYLES ====== */
html, body, .gradio-container { height: 100%; }
#chatbox { height: 70vh; overflow: auto; }
@media (max-width: 640px) { #chatbox { height: 68vh !important; } }
#chatbox * { overflow-wrap: anywhere; word-break: break-word; }
#chatbox pre, #chatbox code, #chatbox .prose pre { white-space: pre-wrap; }
@media (max-width: 480px) { #chatbox { font-size: 0.95rem; } }
"""
demo = gr.ChatInterface(
fn=respond,
chatbot=chat,
title="MiniGPT — Arithmetic + Unit/Group Price",
description=(
"Try: two plus two • 2 acres is 2000, how much is 4 acres? • "
"3 mangoes for $10, price for 5"
),
css=MOBILE_CSS,
)
# Queue for stability (version-safe)
try:
demo.queue(default_concurrency_limit=2, max_size=32, status_update_rate=0.5)
except TypeError:
try:
demo.queue(concurrency_count=2)
except TypeError:
demo.queue()
if __name__ == "__main__":
try:
demo.launch(ssl_verify=False, ssr_mode=False)
except TypeError:
demo.launch()
|