{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "108ad76c-9502-40d3-86b2-7309affc926e", "metadata": {}, "outputs": [], "source": [ "import shutil\n", "import requests\n", "import sys\n", "from typing import Optional, List, Tuple\n", "import json\n", "from langchain_community.llms import HuggingFaceHub" ] }, { "cell_type": "code", "execution_count": 3, "id": "27579e99-9637-4fe5-902c-05c4969ea3aa", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "21ac52ca52fa4910a0e06e3286813c57", "version_major": 2, "version_minor": 0 }, "text/plain": [ "adapter_config.json: 0%| | 0.00/701 [00:00\n", "Answer the question based on your knowledge.\n", "\n", "<|user|>\n", "{question}\n", "\n", "<|assistant|>\n", "\"\"\"\n", "\n", "prompt = PromptTemplate(\n", " input_variables=[\"question\"],\n", " template=prompt_template,\n", ")\n", "\n", "llm_chain = prompt | llm | StrOutputParser()\n", "\n", "def inference(question):\n", " llmAnswer = llm_chain.invoke({\"question\": question})\n", " llmAnswer = llmAnswer.rstrip()\n", " return llmAnswer" ] }, { "cell_type": "code", "execution_count": 6, "id": "9e4c410a-5fdf-4b52-96e2-6745b874cb16", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7862\n", "Running on public URL: https://5eea2cc419906ab3e9.gradio.live\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import gradio as gr\n", "from langchain_core.runnables import RunnablePassthrough\n", "\n", "def predict(question):\n", " return inference(question)\n", " \n", "pred = gr.Interface(\n", " fn=predict,\n", " inputs=[\n", " gr.Textbox(label=\"Question\", value = \"Your Question here......\"),\n", " ],\n", " outputs=\"text\",\n", " title=\"Finetuned Zephr Model in the Database Management Domaain\"\n", ")\n", "\n", "pred.launch(share=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "c7be3ade-8cd6-448b-b608-0182a9743315", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }