Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent internal log_message error from /api/predict #5711

Merged
merged 5 commits into from Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sour-pillows-hug.md
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:Prevent internal log_message from `/api/predict`
7 changes: 4 additions & 3 deletions gradio/helpers.py
Expand Up @@ -1100,7 +1100,10 @@ def log_message(message: str, level: Literal["info", "warning"] = "info"):
from gradio.context import LocalContext

blocks = LocalContext.blocks.get()
if blocks is None: # Function called outside of Gradio
event_id = LocalContext.event_id.get()
if blocks is None or event_id is None:
# Function called outside of Gradio if blocks is None
# Or from /api/predict if event_id is None
if level == "info":
print(message)
elif level == "warning":
Expand All @@ -1111,8 +1114,6 @@ def log_message(message: str, level: Literal["info", "warning"] = "info"):
f"Queueing must be enabled to issue {level.capitalize()}: '{message}'."
)
return
event_id = LocalContext.event_id.get()
assert event_id
blocks._queue.log_message(event_id=event_id, log=message, level=level)


Expand Down