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

Adds LLM to the Playground #9233

Merged
merged 45 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1927290
simple system prompt
aliabd Aug 14, 2024
1ba834e
faster model and streaming and better system prompt
aliabd Aug 15, 2024
9259599
changes
aliabd Aug 21, 2024
fa99a0b
Merge branch 'main' into aliabd/playground-llm
aliabd Aug 30, 2024
5e819e5
changes
aliabd Sep 1, 2024
7cc6b34
add changeset
gradio-pr-bot Sep 1, 2024
7abac1b
formatting
aliabd Sep 1, 2024
e91c593
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 1, 2024
99c4a74
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 2, 2024
abcf5ca
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 3, 2024
2412f73
add placeholder wheel
aliabd Sep 3, 2024
9490435
changes
aliabd Sep 4, 2024
d55d53f
save to db finally working
aliabd Sep 12, 2024
faaf238
clean
aliabd Sep 12, 2024
6691558
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 12, 2024
131c031
fix open in playground button
aliabd Sep 12, 2024
075cbb4
better fix for open in playground
aliabd Sep 12, 2024
9868e0b
changes
aliabd Sep 16, 2024
414583d
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 16, 2024
8e1a0ce
format
aliabd Sep 16, 2024
0a7e5ff
fix
aliabd Sep 16, 2024
560f8b4
try
aliabd Sep 17, 2024
f1a7331
remove
aliabd Sep 17, 2024
4177de2
remove make waveform
aliabd Sep 17, 2024
2a8697a
fix
aliabd Sep 17, 2024
e4330e7
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 17, 2024
b6cc4bf
using fallback mode and other changes
aliabd Sep 17, 2024
40557cb
add show_error
aliabd Sep 17, 2024
1b7027a
fix lite refresh issue
aliabd Sep 17, 2024
e9e1a07
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 17, 2024
fcb2866
fix css
aliabd Sep 17, 2024
18ddb76
add demo
aliabd Sep 17, 2024
928ad1c
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 17, 2024
bff444e
format
aliabd Sep 17, 2024
3423fcd
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 17, 2024
4b29484
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 17, 2024
5f32d68
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 18, 2024
a006329
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 18, 2024
03fea0a
lite using latest wheel
aliabd Sep 18, 2024
243202c
Merge branch '5.0-dev' into aliabd/playground-llm
aliabd Sep 18, 2024
c37069f
cleanup
aliabd Sep 18, 2024
74b674b
Merge branch 'aliabd/playground-llm' of https://github.com/gradio-app…
aliabd Sep 18, 2024
01b9e63
formatting
aliabd Sep 18, 2024
f1dcca9
hack fix for b vs betta
aliabd Sep 19, 2024
24b6bd1
formatting
aliabd Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/witty-worlds-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"website": minor
---

feat:Adds LLM to the Playground
2 changes: 1 addition & 1 deletion demo/annotatedimage_component/run.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: annotatedimage_component"]}, {"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 pathlib\n", "from PIL import Image\n", "import numpy as np\n", "import urllib.request\n", "\n", "source_dir = pathlib.Path(__file__).parent\n", "\n", "urllib.request.urlretrieve(\n", " 'https://gradio-builds.s3.amazonaws.com/demo-files/base.png',\n", " str(source_dir / \"base.png\")\n", ")\n", "urllib.request.urlretrieve(\n", " \"https://gradio-builds.s3.amazonaws.com/demo-files/buildings.png\",\n", " str(source_dir / \"buildings.png\")\n", ")\n", "\n", "base_image = Image.open(str(source_dir / \"base.png\"))\n", "building_image = Image.open(str(source_dir / \"buildings.png\"))\n", "\n", "# Create segmentation mask\n", "building_image = np.asarray(building_image)[:, :, -1] > 0\n", "\n", "with gr.Blocks() as demo:\n", " gr.AnnotatedImage(\n", " value=(base_image, [(building_image, \"buildings\")]),\n", " height=500,\n", " )\n", "\n", "demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: annotatedimage_component"]}, {"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 numpy as np \n", "import requests \n", "from io import BytesIO\n", "from PIL import Image\n", "\n", "base_image = \"https://gradio-docs-json.s3.us-west-2.amazonaws.com/base.png\"\n", "building_image = requests.get(\"https://gradio-docs-json.s3.us-west-2.amazonaws.com/buildings.png\")\n", "building_image = np.asarray(Image.open(BytesIO(building_image.content)))[:, :, -1] > 0\n", "\n", "with gr.Blocks() as demo:\n", " gr.AnnotatedImage(\n", " value=(base_image, [(building_image, \"buildings\")]),\n", " height=500,\n", " )\n", "\n", "demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
27 changes: 7 additions & 20 deletions demo/annotatedimage_component/run.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
import gradio as gr
import pathlib
import numpy as np
import requests
from io import BytesIO
from PIL import Image
import numpy as np
import urllib.request

source_dir = pathlib.Path(__file__).parent

urllib.request.urlretrieve(
'https://gradio-builds.s3.amazonaws.com/demo-files/base.png',
str(source_dir / "base.png")
)
urllib.request.urlretrieve(
"https://gradio-builds.s3.amazonaws.com/demo-files/buildings.png",
str(source_dir / "buildings.png")
)

base_image = Image.open(str(source_dir / "base.png"))
building_image = Image.open(str(source_dir / "buildings.png"))

# Create segmentation mask
building_image = np.asarray(building_image)[:, :, -1] > 0
base_image = "https://gradio-docs-json.s3.us-west-2.amazonaws.com/base.png"
building_image = requests.get("https://gradio-docs-json.s3.us-west-2.amazonaws.com/buildings.png")
building_image = np.asarray(Image.open(BytesIO(building_image.content)))[:, :, -1] > 0

with gr.Blocks() as demo:
gr.AnnotatedImage(
value=(base_image, [(building_image, "buildings")]),
height=500,
)

demo.launch()
demo.launch()
25 changes: 18 additions & 7 deletions js/_website/generate_jsons/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from botocore import UNSIGNED
from botocore.client import Config

from js._website.generate_jsons.src.docs import SYSTEM_PROMPT_8K
from src import changelog, demos, docs, guides

WEBSITE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
Expand Down Expand Up @@ -63,11 +64,12 @@ def get_latest_release():
.strip("'\n")
)
json.dump(
{
"gradio_install": f"pip install https://gradio-builds.s3.amazonaws.com/{sha}/gradio-{version}-py3-none-any.whl",
"gradio_py_client_install": f"pip install 'gradio-client @ git+https://github.com/gradio-app/gradio@{sha}#subdirectory=client/python'",
"gradio_js_client_install": f"npm install https://gradio-builds.s3.amazonaws.com/{sha}/gradio-client-{js_client_version}.tgz",
},
{
"gradio_install": f"pip install https://gradio-builds.s3.amazonaws.com/{sha}/gradio-{version}-py3-none-any.whl",
"gradio_py_client_install": f"pip install 'gradio-client @ git+https://github.com/gradio-app/gradio@{sha}#subdirectory=client/python'",
"gradio_js_client_install": f"npm install https://gradio-builds.s3.amazonaws.com/{sha}/gradio-client-{js_client_version}.tgz",
"gradio_lite_url": f"https://gradio-lite-previews.s3.amazonaws.com/{sha}"
},
j,
)
if not os.path.exists(
Expand All @@ -90,9 +92,18 @@ def create_dir_if_not_exists(path):

demos.generate(make_dir(WEBSITE_DIR, "src/lib/json/demos.json"))
guides.generate(make_dir(WEBSITE_DIR, "src/lib/json/guides/") + "/")
docs.generate(make_dir(WEBSITE_DIR, "src/lib/json/docs.json"))
docs.generate(make_dir(WEBSITE_DIR, "src/lib/templates/docs.json"))
SYSTEM_PROMPT, SYSTEM_PROMPT_8K = docs.generate(make_dir(WEBSITE_DIR, "src/lib/json/docs.json"))
_, _ = docs.generate(make_dir(WEBSITE_DIR, "src/lib/templates/docs.json"))
changelog.generate(make_dir(WEBSITE_DIR, "src/lib/json/changelog.json"))
get_latest_release()

with open(make_dir(WEBSITE_DIR, "src/lib/json/system_prompt.json"), "w+") as f:
json.dump(
{
"SYSTEM": SYSTEM_PROMPT,
"SYSTEM_8K": SYSTEM_PROMPT_8K,
},
f,
)

print("JSON generated! " + make_dir(WEBSITE_DIR, "src/lib/json/"))
121 changes: 120 additions & 1 deletion js/_website/generate_jsons/src/docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,125 @@ def organize_pages():

docs = organize_docs(docs)

gradio_docs = docs["docs"]["gradio"]

SYSTEM_PROMPT = """
Generate code for using the Gradio python library.

The following RULES must be followed. Whenever you are forming a response, ensure all rules have been followed otherwise start over.

RULES:
Only respond with code, not text.
Only respond with valid Python syntax.
Never include backticks in your response such as ``` or ```python.
Never use any external library aside from: gradio, numpy, pandas, plotly, transformers_js and matplotlib.
Do not include any code that is not necessary for the app to run.
Respond with a full Gradio app.
Only respond with one full Gradio app.
Add comments explaining the code, but do not include any text that is not formatted as a Python comment.



Here's an example of a valid response:

# This is a simple Gradio app that greets the user.
import gradio as gr

# Define a function that takes a name and returns a greeting.
def greet(name):
return "Hello " + name + "!"

# Create a Gradio interface that takes a textbox input, runs it through the greet function, and returns output to a textbox.`
demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox")

# Launch the interface.
demo.launch()


Here are some more examples of Gradio apps:


"""



important_demos = ["annotatedimage_component", "audio_component_events", "audio_mixer", "blocks_chained_events", "blocks_essay", "blocks_essay_simple", "blocks_flipper", "blocks_form", "blocks_hello", "blocks_js_load", "blocks_js_methods", "blocks_kinematics", "blocks_layout", "blocks_plug", "blocks_simple_squares", "blocks_update", "blocks_xray", "calculator", "chatbot_consecutive", "chatbot_multimodal", "chatbot_simple", "chatbot_streaming", "chatinterface_multimodal", "custom_css", "datetimes", "diff_texts", "dropdown_key_up", "fake_diffusion", "fake_gan", "filter_records", "function_values", "gallery_component_events", "generate_tone", "hangman", "hello_blocks", "hello_blocks_decorator", "hello_world", "image_editor", "matrix_transpose", "model3D", "on_listener_decorator", "plot_component", "render_merge", "render_split", "reverse_audio_2", "sales_projections", "sentence_builder", "sepia_filter", "sort_records", "streaming_simple", "tabbed_interface_lite", "tax_calculator", "theme_soft", "timer", "timer_simple", "variable_outputs", "video_identity"]

important_demos_8k = ["blocks_essay_simple", "blocks_flipper", "blocks_form", "blocks_hello", "blocks_kinematics", "blocks_layout", "blocks_simple_squares", "calculator", "chatbot_consecutive", "chatbot_simple", "chatbot_streaming", "chatinterface_multimodal", "datetimes", "diff_texts", "dropdown_key_up", "fake_diffusion", "filter_records", "generate_tone", "hangman", "hello_blocks", "hello_blocks_decorator", "hello_world", "image_editor", "matrix_transpose", "model3D", "on_listener_decorator", "plot_component", "render_merge", "render_split", "reverse_audio_2", "sepia_filter", "sort_records", "streaming_simple", "tabbed_interface_lite", "tax_calculator", "theme_soft", "timer", "timer_simple", "variable_outputs", "video_identity"]


def length(demo):
if os.path.exists(os.path.join(DEMOS_DIR, demo, "run.py")):
demo_file = os.path.join(DEMOS_DIR, demo, "run.py")
else:
return 0
with open(demo_file) as run_py:
demo_code = run_py.read()
demo_code = demo_code.replace("# type: ignore", "").replace('if __name__ == "__main__":\n ', "")
return len(demo_code)


SYSTEM_PROMPT += "\n\nHere are some demos showcasing full Gradio apps: \n\n"

SYSTEM_PROMPT_8K = SYSTEM_PROMPT

for demo in important_demos:
if os.path.exists(os.path.join(DEMOS_DIR, demo, "run.py")):
demo_file = os.path.join(DEMOS_DIR, demo, "run.py")
else:
continue
with open(demo_file) as run_py:
demo_code = run_py.read()
demo_code = demo_code.replace("# type: ignore", "").replace('if __name__ == "__main__":\n ', "")
SYSTEM_PROMPT += f"Name: {demo.replace('_', ' ')}\n"
SYSTEM_PROMPT += "Code: \n\n"
SYSTEM_PROMPT += f"{demo_code}\n\n"

for demo in important_demos_8k:
if os.path.exists(os.path.join(DEMOS_DIR, demo, "run.py")):
demo_file = os.path.join(DEMOS_DIR, demo, "run.py")
else:
continue
with open(demo_file) as run_py:
demo_code = run_py.read()
demo_code = demo_code.replace("# type: ignore", "").replace('if __name__ == "__main__":\n ', "")
SYSTEM_PROMPT_8K += f"Name: {demo.replace('_', ' ')}\n"
SYSTEM_PROMPT_8K += "Code: \n\n"
SYSTEM_PROMPT_8K += f"{demo_code}\n\n"


SYSTEM_PROMPT += """

The following RULES must be followed. Whenever you are forming a response, after each sentence ensure all rules have been followed otherwise start over, forming a new response and repeat until the finished response follows all the rules. then send the response.

RULES:
Only respond with code, not text.
Only respond with valid Python syntax.
Never include backticks in your response such as ``` or ```python.
Never use any external library aside from: gradio, numpy, pandas, plotly, transformers_js and matplotlib.
Do not include any code that is not necessary for the app to run.
Respond with a full Gradio app.
Only respond with one full Gradio app.
Add comments explaining the code, but do not include any text that is not formatted as a Python comment.
"""

SYSTEM_PROMPT_8K += """

The following RULES must be followed. Whenever you are forming a response, after each sentence ensure all rules have been followed otherwise start over, forming a new response and repeat until the finished response follows all the rules. then send the response.

RULES:
Only respond with code, not text.
Only respond with valid Python syntax.
Never include backticks in your response such as ``` or ```python.
Never use any external library aside from: gradio, numpy, pandas, plotly, transformers_js and matplotlib.
Do not include any code that is not necessary for the app to run.
Respond with a full Gradio app.
Only respond with one full Gradio app.
Add comments explaining the code, but do not include any text that is not formatted as a Python comment.
"""


def generate(json_path):
with open(json_path, "w+") as f:
json.dump(docs, f)
json.dump(docs, f)
return SYSTEM_PROMPT, SYSTEM_PROMPT_8K
2 changes: 1 addition & 1 deletion js/_website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"mdsvex": "^0.11.0",
"postcss": "^8.4.27",
"prism-svelte": "^0.5.0",
"wrangler": "^3.72.3"
"wrangler": "^3.73.0"
}
}
7 changes: 3 additions & 4 deletions js/_website/src/lib/components/Demos.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
export let highlighted_code: string;
export let url_version: string;

import WHEEL from "$lib/json/wheel.json";

$: url_version;
</script>

<svelte:head>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css"
/>
<link rel="stylesheet" href="{WHEEL.gradio_lite_url}/dist/lite.css" />
</svelte:head>

<div class="hidden lg:block py-2 max-h-[750px] overflow-y-scroll">
Expand Down
Loading
Loading