Skip to content

Commit

Permalink
Merge branch 'main' into 3043-file-types-check
Browse files Browse the repository at this point in the history
  • Loading branch information
abidlabs authored Jan 24, 2023
2 parents 6a59fdf + 2667eb6 commit b7c8560
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 16 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ By [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3014](https://github.
## Bug Fixes:
* Fixes bug where interpretation event was not configured correctly by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2993](https://github.com/gradio-app/gradio/pull/2993)
* Fix relative import bug in reload mode by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2992](https://github.com/gradio-app/gradio/pull/2992)
* Fixes bug where png files were not being recognized when uploadin images by [@abidlabs](https://github.com/abidlabs) in [PR 3002](https://github.com/gradio-app/gradio/pull/3002)
* Fixes bug where png files were not being recognized when uploading images by [@abidlabs](https://github.com/abidlabs) in [PR 3002](https://github.com/gradio-app/gradio/pull/3002)
* Fixes bug where external Spaces could not be loaded and used as functions if they returned files by [@abidlabs](https://github.com/abidlabs) in [PR 3004](https://github.com/gradio-app/gradio/pull/3004)
* Fix bug where file serialization output was not JSON serializable by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2999](https://github.com/gradio-app/gradio/pull/2999)
* Fixes bug where png files were not being recognized when uploading images by [@abidlabs](https://github.com/abidlabs) in [PR 3002](https://github.com/gradio-app/gradio/pull/3002)
Expand All @@ -50,8 +50,10 @@ By [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3014](https://github.
* Added better support for symlinks in the way absolute paths are resolved by [@abidlabs](https://github.com/abidlabs) in [PR 3037](https://github.com/gradio-app/gradio/pull/3037)
* Fix several minor frontend bugs (loading animation, examples as gallery) frontend [@aliabid94](https://github.com/3026) in [PR 2961](https://github.com/gradio-app/gradio/pull/3026).
* Fixes bug that the chatbot sample code does not work with certain input value by [@petrov826](https://github.com/petrov826) in [PR 3039](https://github.com/gradio-app/gradio/pull/3039).
* Fix shadows for form element and ensure focus styles more visible in dark mode [@pngwn](https://github.com/pngwn) in [PR 3042](https://github.com/gradio-app/gradio/pull/3042).
* Fixed bug where the Checkbox and Dropdown change events were not triggered in response to other component changes by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3045](https://github.com/gradio-app/gradio/pull/3045)
* Fixes bug where app would crash if the `file_types` parameter of `gr.File` was not a list by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3048](https://github.com/gradio-app/gradio/pull/3048)
* Fix bug where the queue was not properly restarted after launching a `closed` app by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3022](https://github.com/gradio-app/gradio/pull/3022)

## Documentation Changes:
* SEO improvements to guides by[@aliabd](https://github.com/aliabd) in [PR 2915](https://github.com/gradio-app/gradio/pull/2915)
Expand Down
5 changes: 5 additions & 0 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,9 @@ def close(self, verbose: bool = True) -> None:
self._queue.close()
self.server.close()
self.is_running = False
# So that the startup events (starting the queue)
# happen the next time the app is launched
self.app.startup_events_triggered = False
if verbose:
print("Closing server running on port: {}".format(self.server_port))
except (AttributeError, OSError): # can't close if not running
Expand Down Expand Up @@ -1665,6 +1668,8 @@ def startup_events(self):

if self.enable_queue:
utils.run_coro_in_background(self._queue.start, (self.progress_tracking,))
# So that processing can resume in case the queue was stopped
self._queue.stopped = False
utils.run_coro_in_background(self.create_limiter)

def queue_enabled_for_fn(self, fn_index: int):
Expand Down
8 changes: 7 additions & 1 deletion gradio/queueing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Any, Deque, Dict, List, Tuple

import fastapi
import httpx

from gradio.data_classes import Estimation, PredictBody, Progress, ProgressUnit
from gradio.helpers import TrackedIterable
Expand Down Expand Up @@ -63,8 +64,12 @@ def __init__(
self.max_size = max_size
self.blocks_dependencies = blocks_dependencies
self.access_token = ""
self.queue_client = None

async def start(self, progress_tracking=False):
# So that the client is attached to the running event loop
self.queue_client = httpx.AsyncClient()

run_coro_in_background(self.start_processing)
if progress_tracking:
run_coro_in_background(self.start_progress_tracking)
Expand Down Expand Up @@ -311,13 +316,13 @@ async def call_prediction(self, events: List[Event], batch: bool):
if event.data
]
data.batched = True

response = await AsyncRequest(
method=AsyncRequest.Method.POST,
url=f"{self.server_path}api/predict",
json=dict(data),
headers={"Authorization": f"Bearer {self.access_token}"},
cookies={"access-token": token} if token is not None else None,
client=self.queue_client,
)
return response

Expand Down Expand Up @@ -443,4 +448,5 @@ async def reset_iterators(self, session_hash: str, fn_index: int):
"session_hash": session_hash,
"fn_index": fn_index,
},
client=self.queue_client,
)
2 changes: 1 addition & 1 deletion gradio/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ async def join_queue(
estimation = blocks._queue.get_estimation()
await blocks._queue.send_estimation(event, estimation, rank)
while True:
await asyncio.sleep(60)
await asyncio.sleep(1)
if websocket.application_state == WebSocketState.DISCONNECTED:
return

Expand Down
6 changes: 3 additions & 3 deletions gradio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def __init__(
validation_function: Union[Callable, None] = None,
exception_type: Type[Exception] = Exception,
raise_for_status: bool = False,
client: httpx.AsyncClient | None = None,
**kwargs,
):
"""
Expand All @@ -482,6 +483,7 @@ def __init__(
self._validated_data = None
# Create request
self._request = self._create_request(method, url, **kwargs)
self.client_ = client or self.client

def __await__(self) -> Generator[None, Any, "AsyncRequest"]:
"""
Expand All @@ -503,9 +505,7 @@ async def __run(self) -> AsyncRequest:
"""
try:
# Send the request and get the response.
self._response: httpx.Response = await AsyncRequest.client.send(
self._request
)
self._response: httpx.Response = await self.client_.send(self._request)
# Raise for _status
self._status = self._response.status_code
if self._raise_for_status:
Expand Down
36 changes: 36 additions & 0 deletions test/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,42 @@ def test_custom_css(self):

assert block.css == css

@pytest.mark.asyncio
async def test_restart_after_close(self):
io = gr.Interface(lambda s: s, gr.Textbox(), gr.Textbox()).queue()
io.launch(prevent_thread_lock=True)

async with websockets.connect(
f"{io.local_url.replace('http', 'ws')}queue/join"
) as ws:
completed = False
while not completed:
msg = json.loads(await ws.recv())
if msg["msg"] == "send_data":
await ws.send(json.dumps({"data": ["freddy"], "fn_index": 0}))
if msg["msg"] == "send_hash":
await ws.send(json.dumps({"fn_index": 0, "session_hash": "shdce"}))
if msg["msg"] == "process_completed":
completed = True
assert msg["output"]["data"][0] == "freddy"

io.close()
io.launch(prevent_thread_lock=True)

async with websockets.connect(
f"{io.local_url.replace('http', 'ws')}queue/join"
) as ws:
completed = False
while not completed:
msg = json.loads(await ws.recv())
if msg["msg"] == "send_data":
await ws.send(json.dumps({"data": ["Victor"], "fn_index": 0}))
if msg["msg"] == "send_hash":
await ws.send(json.dumps({"fn_index": 0, "session_hash": "shdce"}))
if msg["msg"] == "process_completed":
completed = True
assert msg["output"]["data"][0] == "Victor"


class TestComponentsInBlocks:
def test_slider_random_value_config(self):
Expand Down
2 changes: 2 additions & 0 deletions test/test_queueing.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ async def test_process_event(self, mock_request, queue: Queue, mock_event: Event
"session_hash": mock_event.session_hash,
"fn_index": mock_event.fn_index,
},
client=None,
)

@pytest.mark.asyncio
Expand Down Expand Up @@ -305,6 +306,7 @@ async def test_process_event_handles_exception_during_disconnect(
"session_hash": mock_event.session_hash,
"fn_index": mock_event.fn_index,
},
client=None,
)


Expand Down
7 changes: 1 addition & 6 deletions ui/packages/form/src/Dropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
<!-- svelte-ignore a11y-label-has-associated-control -->
<label>
<BlockTitle {show_label}>{label}</BlockTitle>
<!-- <select bind:value {disabled}>
{#each choices as choice}
<option>{choice}</option>
{/each}
</select> -->

{#if !multiselect}
<select bind:value {disabled}>
Expand All @@ -45,7 +40,7 @@
position: relative;
outline: none !important;
box-shadow: 0 0 0 var(--shadow-spread) var(--ring-color),
var(--input-shadow);
var(--shadow-inset);
border: 1px solid var(--input-border-color-base);
border-radius: var(--radius-lg);
background-color: var(--input-background-base);
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/form/src/Number.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
position: relative;
outline: none !important;
box-shadow: 0 0 0 var(--shadow-spread) var(--ring-color),
var(--input-shadow);
var(--shadow-inset);
border: 1px solid var(--input-border-color-base);
border-radius: var(--radius-lg);
background: var(--input-background-base);
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/form/src/Radio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
--ring-color: transparent;
position: relative;
box-shadow: 0 0 0 var(--shadow-spread) var(--ring-color),
var(--input-shadow);
var(--shadow-inset);
border: 1px solid var(--checkbox-border-color-base);
border-radius: var(--radius-full);
background-color: var(--checkbox-background-base);
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/form/src/Range.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
position: relative;
outline: none !important;
box-shadow: 0 0 0 var(--shadow-spread) var(--ring-color),
var(--input-shadow);
var(--shadow-inset);
border: 1px solid var(--input-border-color-base);
border-radius: var(--radius-lg);
background: var(--input-background-base);
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/theme/src/generate_theme.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const foundation_dark = {
}
},
shadow: {
spread: "1px"
spread: "2px"
}
};

Expand Down

0 comments on commit b7c8560

Please sign in to comment.