{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Xây dựng bản demo đầu tiên của bạn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Install the Transformers, Datasets, and Evaluate libraries to run this notebook." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install datasets evaluate transformers[sentencepiece]\n", "!pip install gradio" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import gradio as gr\n", "\n", "\n", "def greet(name):\n", " return \"Hello \" + name\n", "\n", "\n", "demo = gr.Interface(fn=greet, inputs=\"text\", outputs=\"text\")\n", "\n", "demo.launch()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import gradio as gr\n", "\n", "\n", "def greet(name):\n", " return \"Hello \" + name\n", "\n", "\n", "# Chúng tôi khởi tạo lớp Textbox\n", "textbox = gr.Textbox(label=\"Type your name here:\", placeholder=\"John Doe\", lines=2)\n", "\n", "gr.Interface(fn=greet, inputs=textbox, outputs=\"text\").launch()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from transformers import pipeline\n", "\n", "model = pipeline(\"text-generation\")\n", "\n", "\n", "def predict(prompt):\n", " completion = model(prompt)[0][\"generated_text\"]\n", " return completion" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import gradio as gr\n", "\n", "gr.Interface(fn=predict, inputs=\"text\", outputs=\"text\").launch()" ] } ], "metadata": { "colab": { "name": "Xây dựng bản demo đầu tiên của bạn", "provenance": [] } }, "nbformat": 4, "nbformat_minor": 4 }