Upload folder using huggingface_hub
Browse files- requirements.txt +2 -2
- run.ipynb +1 -1
- run.py +6 -4
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
gradio-client @ git+https://github.com/gradio-app/gradio@
|
2 |
-
https://gradio-pypi-previews.s3.amazonaws.com/
|
|
|
1 |
+
gradio-client @ git+https://github.com/gradio-app/gradio@ab25fb9adb4e0401a060cdd07c0985483075123c#subdirectory=client/python
|
2 |
+
https://gradio-pypi-previews.s3.amazonaws.com/ab25fb9adb4e0401a060cdd07c0985483075123c/gradio-5.31.0-py3-none-any.whl
|
run.ipynb
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: i18n"]}, {"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", "\n", "# create an i18n instance with translations for different languages\n", "i18n = gr.I18n(\n", " en={\"name_label\": \"Your Name\", \"submit_button\": \"Greet\", \"john_doe\": \"John English\", \"result_label\": \"Result\"},\n", " es={\"name_label\": \"Tu Nombre\", \"submit_button\": \"Saludar\", \"john_doe\": \"John Spanish\", \"result_label\": \"Resultado\"},\n", " fr={\"name_label\": \"Votre Nom\", \"submit_button\": \"Saluer\", \"john_doe\": \"John French\", \"result_label\": \"R\u00e9sultat\"},\n", " de={\"name_label\": \"Dein Name\", \"submit_button\": \"Gr\u00fc\u00dfen\", \"john_doe\": \"John German\", \"result_label\": \"Ergebnis\"},\n", ")\n", "\n", "def add_hello_world(name):\n", " return \"hello \" + name\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " # use i18n() for any string that should be translated\n", " name_input = gr.Textbox(label=i18n(\"name_label\"), value=i18n(\"john_doe\"))\n", "\n", " with gr.Row():\n", " output_text = gr.Textbox(label=i18n(\"result_label\"))\n", "\n", " with gr.Row():\n", " greet_btn = gr.Button(value=i18n(\"submit_button\"))\n", "\n", " with gr.Row():\n", " reset_btn = gr.Button(\"Reset Name\")\n", "\n", " greet_btn.click(fn=add_hello_world, inputs=name_input, outputs=output_text)\n", " reset_btn.click(fn=lambda: i18n(\"john_doe\"), inputs=None, outputs=name_input)\n", "\n", " gr.Markdown(\"\"\"\n", " This demo shows Gradio's internationalization (i18n) functionality. \n", " The interface automatically displays text in the user's browser language \n", " (if available in our translations), or falls back to English.\n", " \"\"\")\n", "\n", "if __name__ == \"__main__\":\n", " # pass i18n to the launch function\n", " demo.launch(i18n=i18n)\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: i18n"]}, {"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", "\n", "# create an i18n instance with translations for different languages\n", "i18n = gr.I18n(\n", " en={\"greeting\": \"Hello, welcome to my app!\", \"name_label\": \"Your Name\", \"submit_button\": \"Greet\", \"john_doe\": \"John English\", \"result_label\": \"Result\"},\n", " es={\"greeting\": \"\u00a1Hola, bienvenido a mi aplicaci\u00f3n!\", \"name_label\": \"Tu Nombre\", \"submit_button\": \"Saludar\", \"john_doe\": \"John Spanish\", \"result_label\": \"Resultado\"},\n", " fr={\"greeting\": \"Bonjour, bienvenue dans mon application!\", \"name_label\": \"Votre Nom\", \"submit_button\": \"Saluer\", \"john_doe\": \"John French\", \"result_label\": \"R\u00e9sultat\"},\n", " de={\"greeting\": \"Hallo, willkommen in meiner App!\", \"name_label\": \"Dein Name\", \"submit_button\": \"Gr\u00fc\u00dfen\", \"john_doe\": \"John German\", \"result_label\": \"Ergebnis\"},\n", ")\n", "\n", "def add_hello_world(name):\n", " return \"hello \" + name\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(value=i18n(\"greeting\"))\n", "\n", " with gr.Row():\n", " # use i18n() for any string that should be translated\n", " name_input = gr.Textbox(label=i18n(\"name_label\"), value=i18n(\"john_doe\"))\n", "\n", " with gr.Row():\n", " output_text = gr.Textbox(label=i18n(\"result_label\"))\n", "\n", " with gr.Row():\n", " greet_btn = gr.Button(value=i18n(\"submit_button\"))\n", "\n", " with gr.Row():\n", " reset_btn = gr.Button(\"Reset Name\")\n", "\n", " greet_btn.click(fn=add_hello_world, inputs=name_input, outputs=output_text)\n", " reset_btn.click(fn=lambda: i18n(\"john_doe\"), inputs=None, outputs=name_input)\n", "\n", " gr.Markdown(\"\"\"\n", " This demo shows Gradio's internationalization (i18n) functionality. \n", " The interface automatically displays text in the user's browser language \n", " (if available in our translations), or falls back to English.\n", " \"\"\")\n", "\n", "if __name__ == \"__main__\":\n", " # pass i18n to the launch function\n", " demo.launch(i18n=i18n)\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
@@ -2,16 +2,18 @@ import gradio as gr
|
|
2 |
|
3 |
# create an i18n instance with translations for different languages
|
4 |
i18n = gr.I18n(
|
5 |
-
en={"name_label": "Your Name", "submit_button": "Greet", "john_doe": "John English", "result_label": "Result"},
|
6 |
-
es={"name_label": "Tu Nombre", "submit_button": "Saludar", "john_doe": "John Spanish", "result_label": "Resultado"},
|
7 |
-
fr={"name_label": "Votre Nom", "submit_button": "Saluer", "john_doe": "John French", "result_label": "R茅sultat"},
|
8 |
-
de={"name_label": "Dein Name", "submit_button": "Gr眉脽en", "john_doe": "John German", "result_label": "Ergebnis"},
|
9 |
)
|
10 |
|
11 |
def add_hello_world(name):
|
12 |
return "hello " + name
|
13 |
|
14 |
with gr.Blocks() as demo:
|
|
|
|
|
15 |
with gr.Row():
|
16 |
# use i18n() for any string that should be translated
|
17 |
name_input = gr.Textbox(label=i18n("name_label"), value=i18n("john_doe"))
|
|
|
2 |
|
3 |
# create an i18n instance with translations for different languages
|
4 |
i18n = gr.I18n(
|
5 |
+
en={"greeting": "Hello, welcome to my app!", "name_label": "Your Name", "submit_button": "Greet", "john_doe": "John English", "result_label": "Result"},
|
6 |
+
es={"greeting": "隆Hola, bienvenido a mi aplicaci贸n!", "name_label": "Tu Nombre", "submit_button": "Saludar", "john_doe": "John Spanish", "result_label": "Resultado"},
|
7 |
+
fr={"greeting": "Bonjour, bienvenue dans mon application!", "name_label": "Votre Nom", "submit_button": "Saluer", "john_doe": "John French", "result_label": "R茅sultat"},
|
8 |
+
de={"greeting": "Hallo, willkommen in meiner App!", "name_label": "Dein Name", "submit_button": "Gr眉脽en", "john_doe": "John German", "result_label": "Ergebnis"},
|
9 |
)
|
10 |
|
11 |
def add_hello_world(name):
|
12 |
return "hello " + name
|
13 |
|
14 |
with gr.Blocks() as demo:
|
15 |
+
gr.Markdown(value=i18n("greeting"))
|
16 |
+
|
17 |
with gr.Row():
|
18 |
# use i18n() for any string that should be translated
|
19 |
name_input = gr.Textbox(label=i18n("name_label"), value=i18n("john_doe"))
|