Upload with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 🔥
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 3.
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
|
| 2 |
---
|
| 3 |
+
title: code
|
| 4 |
emoji: 🔥
|
| 5 |
+
colorFrom: indigo
|
| 6 |
+
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
+
sdk_version: 3.21.0
|
| 9 |
+
app_file: run.py
|
| 10 |
pinned: false
|
| 11 |
---
|
|
|
|
|
|
file.css
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.class {
|
| 2 |
+
color: blue;
|
| 3 |
+
}
|
| 4 |
+
|
| 5 |
+
#id {
|
| 6 |
+
color: pink;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
div {
|
| 10 |
+
color: purple;
|
| 11 |
+
}
|
run.ipynb
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: code"]}, {"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", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/code/file.css"]}, {"cell_type": "code", "execution_count": null, "id": 44380577570523278879349135829904343037, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import os\n", "from time import sleep\n", "\n", "\n", "css_file = os.path.join(os.path.abspath(''), \"file.css\")\n", "\n", "\n", "def set_lang(language):\n", " print(language)\n", " return gr.Code.update(language=language)\n", "\n", "\n", "def set_lang_from_path():\n", " sleep(1)\n", " return gr.Code.update(css_file, language=\"css\")\n", "\n", "\n", "def code(language, code):\n", " return gr.Code.update(code, language=language)\n", "\n", "\n", "io = gr.Interface(lambda x: x, \"code\", \"code\")\n", "\n", "with gr.Blocks() as demo:\n", " lang = gr.Dropdown(value=\"python\", choices=gr.Code.languages)\n", " with gr.Row():\n", " code_in = gr.Code(language=\"python\", label=\"Input\")\n", " code_out = gr.Code(label=\"Ouput\")\n", " btn = gr.Button(\"Run\")\n", " btn_two = gr.Button(\"Load File\")\n", "\n", " lang.change(set_lang, inputs=lang, outputs=code_in)\n", " btn.click(code, inputs=[lang, code_in], outputs=code_out)\n", " btn_two.click(set_lang_from_path, inputs=None, outputs=code_out)\n", " io.render()\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from time import sleep
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
css_file = os.path.join(os.path.dirname(__file__), "file.css")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def set_lang(language):
|
| 10 |
+
print(language)
|
| 11 |
+
return gr.Code.update(language=language)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def set_lang_from_path():
|
| 15 |
+
sleep(1)
|
| 16 |
+
return gr.Code.update(css_file, language="css")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def code(language, code):
|
| 20 |
+
return gr.Code.update(code, language=language)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
io = gr.Interface(lambda x: x, "code", "code")
|
| 24 |
+
|
| 25 |
+
with gr.Blocks() as demo:
|
| 26 |
+
lang = gr.Dropdown(value="python", choices=gr.Code.languages)
|
| 27 |
+
with gr.Row():
|
| 28 |
+
code_in = gr.Code(language="python", label="Input")
|
| 29 |
+
code_out = gr.Code(label="Ouput")
|
| 30 |
+
btn = gr.Button("Run")
|
| 31 |
+
btn_two = gr.Button("Load File")
|
| 32 |
+
|
| 33 |
+
lang.change(set_lang, inputs=lang, outputs=code_in)
|
| 34 |
+
btn.click(code, inputs=[lang, code_in], outputs=code_out)
|
| 35 |
+
btn_two.click(set_lang_from_path, inputs=None, outputs=code_out)
|
| 36 |
+
io.render()
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
demo.launch()
|