Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyaboulton committed Mar 28, 2024
1 parent beb28f3 commit 068afe2
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 107 deletions.
Empty file removed demo/calculator/bar/__init__.py
Empty file.
12 changes: 0 additions & 12 deletions demo/calculator/bar/baz.py

This file was deleted.

31 changes: 0 additions & 31 deletions demo/calculator/cert.pem

This file was deleted.

52 changes: 0 additions & 52 deletions demo/calculator/key.pem

This file was deleted.

2 changes: 1 addition & 1 deletion demo/calculator/run.ipynb
@@ -1 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: calculator"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "os.mkdir('examples')\n", "!wget -q -O examples/log.csv https://github.com/gradio-app/gradio/raw/main/demo/calculator/examples/log.csv"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "#from foo import BAR\n", "#\n", "def calculator(num1, operation, num2):\n", " if operation == \"add\":\n", " return num1 + num2\n", " elif operation == \"subtract\":\n", " return num1 - num2\n", " elif operation == \"multiply\":\n", " return num1 * num2\n", " elif operation == \"divide\":\n", " if num2 == 0:\n", " raise gr.Error(\"Cannot divide by zero!\")\n", " return num1 / num2\n", "\n", "demo = gr.Interface(\n", " calculator,\n", " [\n", " \"number\", \n", " gr.Radio([\"add\", \"subtract\", \"multiply\", \"divide\"]),\n", " \"number\"\n", " ],\n", " \"number\",\n", " examples=[\n", " [45, \"add\", 3],\n", " [3.14, \"divide\", 2],\n", " [144, \"multiply\", 2.5],\n", " [0, \"subtract\", 1.2],\n", " ],\n", " title=\"Toy Calculator\",\n", " description=\"Here's a sample toy calculator. Allows you to calculate things like $2+2=4$\",\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: calculator"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "os.mkdir('bar')\n", "!wget -q -O bar/__init__.py https://github.com/gradio-app/gradio/raw/main/demo/calculator/bar/__init__.py\n", "!wget -q -O bar/baz.py https://github.com/gradio-app/gradio/raw/main/demo/calculator/bar/baz.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/calculator/cert.pem\n", "os.mkdir('examples')\n", "!wget -q -O examples/log.csv https://github.com/gradio-app/gradio/raw/main/demo/calculator/examples/log.csv\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/calculator/foo.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/calculator/key.pem"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "#from foo import BAR\n", "#\n", "def calculator(num1, operation, num2):\n", " if operation == \"add\":\n", " return num1 + num2\n", " elif operation == \"subtract\":\n", " return num1 - num2\n", " elif operation == \"multiply\":\n", " return num1 * num2\n", " elif operation == \"divide\":\n", " if num2 == 0:\n", " raise gr.Error(\"Cannot divide by zero!\")\n", " return num1 / num2\n", "\n", "demo = gr.Interface(\n", " calculator,\n", " [\n", " \"number\", \n", " gr.Radio([\"add\", \"subtract\", \"multiply\", \"divide\"]),\n", " \"number\"\n", " ],\n", " \"number\",\n", " examples=[\n", " [45, \"add\", 3],\n", " [3.14, \"divide\", 2],\n", " [144, \"multiply\", 2.5],\n", " [0, \"subtract\", 1.2],\n", " ],\n", " title=\"Toy Calculator\",\n", " description=\"Here's a sample toy calculator. Allows you to calculate things like $2+2=4$\",\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
6 changes: 2 additions & 4 deletions demo/calculator/run.py
Expand Up @@ -10,7 +10,7 @@ def calculator(num1, operation, num2):
return num1 * num2
elif operation == "divide":
if num2 == 0:
raise ValueError("Cannot divide by zero!")
raise gr.Error("Cannot divide by zero!")
return num1 / num2

demo = gr.Interface(
Expand All @@ -32,6 +32,4 @@ def calculator(num1, operation, num2):
)

if __name__ == "__main__":
demo.launch(prevent_thread_lock=True)
breakpoint()
2 + 2
demo.launch()
1 change: 0 additions & 1 deletion demo/cancel_events/cancel_events_output_log.txt

This file was deleted.

4 changes: 1 addition & 3 deletions demo/hangman/run.py
Expand Up @@ -32,6 +32,4 @@ def guess_letter(letter, used_letters):
[used_letters_var, used_letters_box, hangman]
)
if __name__ == "__main__":
app, _, _ = demo.launch(prevent_thread_lock=True)
breakpoint()
2 + 2
demo.launch()
2 changes: 1 addition & 1 deletion demo/hello_login/run.ipynb
@@ -1 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: hello_login"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import argparse\n", "import sys\n", "\n", "parser = argparse.ArgumentParser()\n", "parser.add_argument(\"--name\", type=str, default=\"User\")\n", "args, unknown = parser.parse_known_args()\n", "print(sys.argv)\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(f\"# Greetings {args.name}!\")\n", " inp = gr.Textbox()\n", " out = gr.Textbox()\n", "\n", " inp.change(fn=lambda x: x, inputs=inp, outputs=out)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: hello_login"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import argparse\n", "import sys\n", "\n", "parser = argparse.ArgumentParser()\n", "parser.add_argument(\"--name\", type=str, default=\"User\")\n", "args, unknown = parser.parse_known_args()\n", "print(sys.argv)\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(f\"# Greetings {args.name}!\")\n", " inp = gr.Textbox()\n", " out = gr.Textbox()\n", "\n", " inp.change(fn=lambda x: x, inputs=inp, outputs=out)\n", "\n", " def unload(req: gr.Request):\n", " print(req.request.path_params)\n", " print(\"UNLOADING\")\n", "\n", " demo.unload(unload)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch(auth=(\"admin\", \"admin\"))"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
8 changes: 7 additions & 1 deletion demo/hello_login/run.py
Expand Up @@ -14,5 +14,11 @@

inp.change(fn=lambda x: x, inputs=inp, outputs=out)

def unload(req: gr.Request):
print(req.request.path_params)
print("UNLOADING")

demo.unload(unload)

if __name__ == "__main__":
demo.launch()
demo.launch(auth=("admin", "admin"))
1 change: 0 additions & 1 deletion gradio/queueing.py
Expand Up @@ -581,7 +581,6 @@ async def process_events(
),
)
awake_events = [event for event in awake_events if event.alive]
print("AWAKE EVENTS", awake_events)
if not awake_events:
return
try:
Expand Down

0 comments on commit 068afe2

Please sign in to comment.