aliabd HF Staff commited on
Commit
9574c37
·
verified ·
1 Parent(s): d2b76c9

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. run.ipynb +1 -1
  2. run.py +1 -3
run.ipynb CHANGED
@@ -1 +1 @@
1
- {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: english_translator"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio transformers torch"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "from transformers import pipeline\n", "\n", "pipe = pipeline(\"translation\", model=\"t5-base\")\n", "\n", "\n", "def translate(text):\n", " return pipe(text)[0][\"translation_text\"] # type: ignore\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " english = gr.Textbox(label=\"English text\")\n", " translate_btn = gr.Button(value=\"Translate\")\n", " with gr.Column():\n", " german = gr.Textbox(label=\"German Text\")\n", "\n", " translate_btn.click(translate, inputs=english, outputs=german, api_name=\"translate-to-german\")\n", " examples = gr.Examples(examples=[\"I went to the supermarket yesterday.\", \"Helen is a good swimmer.\"],\n", " inputs=[english])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: english_translator"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio transformers torch"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "from transformers import pipeline\n", "\n", "pipe = pipeline(\"translation\", model=\"t5-base\")\n", "\n", "def translate(text):\n", " return pipe(text)[0][\"translation_text\"] # type: ignore\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " english = gr.Textbox(label=\"English text\")\n", " translate_btn = gr.Button(value=\"Translate\")\n", " with gr.Column():\n", " german = gr.Textbox(label=\"German Text\")\n", "\n", " translate_btn.click(translate, inputs=english, outputs=german, api_name=\"translate-to-german\")\n", " examples = gr.Examples(examples=[\"I went to the supermarket yesterday.\", \"Helen is a good swimmer.\"],\n", " inputs=[english])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -4,11 +4,9 @@ from transformers import pipeline
4
 
5
  pipe = pipeline("translation", model="t5-base")
6
 
7
-
8
  def translate(text):
9
  return pipe(text)[0]["translation_text"] # type: ignore
10
 
11
-
12
  with gr.Blocks() as demo:
13
  with gr.Row():
14
  with gr.Column():
@@ -22,4 +20,4 @@ with gr.Blocks() as demo:
22
  inputs=[english])
23
 
24
  if __name__ == "__main__":
25
- demo.launch()
 
4
 
5
  pipe = pipeline("translation", model="t5-base")
6
 
 
7
  def translate(text):
8
  return pipe(text)[0]["translation_text"] # type: ignore
9
 
 
10
  with gr.Blocks() as demo:
11
  with gr.Row():
12
  with gr.Column():
 
20
  inputs=[english])
21
 
22
  if __name__ == "__main__":
23
+ demo.launch()