Spaces:
Running
Running
Download app.py from codeninja3d/minigpt-multi: direct link, hf CLI and curl.
- Browser
- Download file 2.15 kB
-
https://huggingface.co/spaces/codeninja3d/minigpt-multi/resolve/main/app.py
- Command line
-
hf download hf://spaces/codeninja3d/minigpt-multi/app.py
-
curl -L -o app.py https://huggingface.co/spaces/codeninja3d/minigpt-multi/resolve/main/app.py
2.15 kB
| # 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() | |