Skip to content

async-function-support#1190

Merged
omerXfaruq merged 7 commits intomainfrom
async-function-support
May 11, 2022
Merged

async-function-support#1190
omerXfaruq merged 7 commits intomainfrom
async-function-support

Conversation

@omerXfaruq
Copy link
Copy Markdown
Contributor

@omerXfaruq omerXfaruq commented May 9, 2022

  • support async functions with Blocks
  • refactor app a bit

Related: #727

This took some time to correctly work on Interface, it seems lambda functions are always wicked :D

@omerXfaruq omerXfaruq requested review from abidlabs and aliabid94 May 9, 2022 09:44
@omerXfaruq
Copy link
Copy Markdown
Contributor Author

omerXfaruq commented May 9, 2022

Currently only Blocks is supported(#1212) and you can try this example:

import asyncio
import gradio as gr


async def async_func(*args):
    await asyncio.sleep(5)
    return "Hello after 5 second"


with gr.Blocks() as demo:
    text = gr.components.Textbox()
    button = gr.components.Button()
    button.click(async_func, text, text)
    demo.launch()

raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="Not authenticated"
)
class App(FastAPI):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No functional change here, just tidied things a little bit into OOP.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@omerXfaruq omerXfaruq marked this pull request as draft May 9, 2022 10:54
- add async function support to Blocks
@omerXfaruq omerXfaruq force-pushed the async-function-support branch from d2e4654 to 204eb45 Compare May 11, 2022 10:32
@omerXfaruq omerXfaruq marked this pull request as ready for review May 11, 2022 10:37
- resolve conflicts
@omerXfaruq omerXfaruq force-pushed the async-function-support branch from 0daf25a to bdf58b6 Compare May 11, 2022 10:56
@omerXfaruq omerXfaruq requested review from abidlabs and aliabid94 May 11, 2022 11:12
- add error to Interface for async functions
@abidlabs
Copy link
Copy Markdown
Member

Looking great @farukozderim!

I would only that we add a test in test_blocks with an async function to ensure everything works as expected.

@abidlabs abidlabs closed this May 11, 2022
@abidlabs abidlabs reopened this May 11, 2022
@omerXfaruq
Copy link
Copy Markdown
Contributor Author

Looking great @farukozderim!

I would only that we add a test in test_blocks with an async function to ensure everything works as expected.

Great idea!

- add test packages
- add test packages
@omerXfaruq omerXfaruq merged commit a88c017 into main May 11, 2022
@omerXfaruq omerXfaruq deleted the async-function-support branch May 11, 2022 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants