Spaces:
Sleeping
Sleeping
Rajan Sharma
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,25 @@ from functools import lru_cache
|
|
| 5 |
import gradio as gr
|
| 6 |
import torch
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Timezone (Python 3.9+)
|
| 9 |
try:
|
| 10 |
from zoneinfo import ZoneInfo
|
|
@@ -256,13 +275,13 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
|
|
| 256 |
fn=chat_fn,
|
| 257 |
type="messages",
|
| 258 |
additional_inputs=[tz_box],
|
| 259 |
-
chatbot=gr.Chatbot(label="", show_label=False), #
|
| 260 |
examples=[
|
| 261 |
["What are the symptoms of hypertension?", ""],
|
| 262 |
["What are common drug interactions with aspirin?", ""],
|
| 263 |
["What are the warning signs of diabetes?", ""],
|
| 264 |
],
|
| 265 |
-
cache_examples=
|
| 266 |
)
|
| 267 |
|
| 268 |
if __name__ == "__main__":
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
import torch
|
| 7 |
|
| 8 |
+
# -------------------
|
| 9 |
+
# Writable caches for HF + Gradio (fixes PermissionError in Spaces)
|
| 10 |
+
# -------------------
|
| 11 |
+
os.environ.setdefault("HF_HOME", "/data/.cache/huggingface")
|
| 12 |
+
os.environ.setdefault("TRANSFORMERS_CACHE", "/data/.cache/huggingface/transformers")
|
| 13 |
+
os.environ.setdefault("HF_HUB_CACHE", "/data/.cache/huggingface/hub")
|
| 14 |
+
os.environ.setdefault("GRADIO_TEMP_DIR", "/data/gradio")
|
| 15 |
+
os.environ.setdefault("GRADIO_CACHE_DIR", "/data/gradio")
|
| 16 |
+
|
| 17 |
+
for p in [
|
| 18 |
+
"/data/.cache/huggingface/transformers",
|
| 19 |
+
"/data/.cache/huggingface/hub",
|
| 20 |
+
"/data/gradio",
|
| 21 |
+
]:
|
| 22 |
+
try:
|
| 23 |
+
os.makedirs(p, exist_ok=True)
|
| 24 |
+
except Exception:
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
# Timezone (Python 3.9+)
|
| 28 |
try:
|
| 29 |
from zoneinfo import ZoneInfo
|
|
|
|
| 275 |
fn=chat_fn,
|
| 276 |
type="messages",
|
| 277 |
additional_inputs=[tz_box],
|
| 278 |
+
chatbot=gr.Chatbot(label="", show_label=False, type="messages"), # aligned type + no label
|
| 279 |
examples=[
|
| 280 |
["What are the symptoms of hypertension?", ""],
|
| 281 |
["What are common drug interactions with aspirin?", ""],
|
| 282 |
["What are the warning signs of diabetes?", ""],
|
| 283 |
],
|
| 284 |
+
cache_examples=False, # prevent permission error in Spaces
|
| 285 |
)
|
| 286 |
|
| 287 |
if __name__ == "__main__":
|