{ "cells": [ { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "import torch\n", "import pickle\n", "from language import Language\n", "from utility import Encoder, Decoder, encoderBlock, decoderBlock, MultiHeadAttention, Head, FeedForward\n", "import warnings\n", "from typing import List\n", "warnings.filterwarnings(\"ignore\", category=FutureWarning)\n" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['लॉक्सलाक्राक्यालालासी']" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = 'a' * 1\n", "generate([s])" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'^थ्रालाष्राप्टोार्फ्रास्रफ्फ्फ्'" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "output_lang.decode(o.tolist()[0])" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "tensor([20, 4, 5, 12, 4, 3])" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = \"pankaj\"\n", "torch.tensor(input_lang.encode(s), device=device, dtype=torch.long)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7864\n", "\n", "Could not create share link. Please check your internet connection or our status page: https://status.gradio.app.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import requests\n", "import gradio as gr\n", "\n", "# Define the API endpoint\n", "API_URL = \"http://127.0.0.1:8000/trans\"\n", "\n", "# Function to call the FastAPI backend\n", "def predict(user_input):\n", " # Prepare the data to send to the FastAPI API\n", " payload = {\"query\": user_input}\n", " \n", " # Make a request to the FastAPI backend\n", " response = requests.post(API_URL, json=payload)\n", " \n", " # Get the response JSON\n", " result = response.json()\n", " \n", " # Extract the answer \n", " return \" \".join(result[\"response\"])\n", " \n", "\n", "# Launch the Gradio interface\n", "if __name__ == \"__main__\":\n", " gr.Interface(predict,\n", " inputs=['textbox'],\n", " outputs=['text']).launch(share=True)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import gradio as gr\n", "\n", "def greet(name, intensity):\n", " return \"Hello, \" + name + \"!\" * int(intensity)\n", "\n", "demo = gr.Interface(\n", " fn=greet,\n", " inputs=[\"text\", \"slider\"],\n", " outputs=[\"text\"],\n", ")\n", "\n", "demo.launch()\n" ] } ], "metadata": { "kernelspec": { "display_name": "transliteration", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.7" } }, "nbformat": 4, "nbformat_minor": 2 }