Quick Start - Generative AI with Gradio User Interface

Quick Start - Generative AI with Gradio User Interface

Building Generative AI application with GenAI APIs like Open AI is quite easy but one of the challenges with ML Engineers and Data Scientists is to build or integrate their App with UI to demonstrate it to clients.

It is always nice to demonstrate your applications using user interface. UI is also very helpful to collect the feedback and show the demo.

Gradio makes it easy for you!!

With Gradio, you can quickly build your user interface with few lines of code.

We will create quick start GenAI application using Langchain and OpenAI and then create User Interface with Gradio:

Step 1: Install the required Libraries:

!pip install openai
!pip install langchain
!pip install gradioi        

Step 2: Import Libraries and add your Open AI API key.

import openai
from langchain import PromptTemplate
from langchain.llms import OpenAI
openai.api_key = "<API_KEY>"
llm = OpenAI(openai_api_key=openai.api_key , temperature=0)
        

Step 3: Create your helper function or Prompt with the help of Prompt Templates and Langchain

def get_completion(Loc):
? template = """ I want to travel {location}.what should I do there? response in one short sentence """
? prompt = PromptTemplate(input_variables=["location"],template=template, ?)
? final_prompt = prompt.format(location=Loc)
? response = llm(final_prompt)
? return response:

        

Step 4: Create quick User Interface to demonstrate your application:

import gradio as g
def get_response(input):
? ? output = get_completion(input)
? ? return output
? ? 
gr.close_all()
demo = gr.Interface(fn=get_response, inputs="text", outputs="text")
demo.launch(share=True)        

After execution above step, you would get below User Interface.

Enter your location in input which you want to explore and see the output from LLM in Output Textbox:

No alt text provided for this image


Congratulations!!

You have created a sample UI for your GenAI Application!!

Happy Learning!!

要查看或添加评论,请登录

Ruchi A.的更多文章

  • Generative AI -Opportunities and Challenges

    Generative AI -Opportunities and Challenges

    ChatGPT and Generative AI are no more buzz words for anyone!! Generative AI can do lots of fantastic tasks for example,…

  • Scalable Machine Learning with Google Cloud

    Scalable Machine Learning with Google Cloud

    Adoption of AI and ML is becoming necessary for industries to solve real world complex problems and to achieve their…

  • MLOps - AI from POC to Production

    MLOps - AI from POC to Production

    Adoption of AI and ML is becoming necessary for industries to solve real world complex problems and to achieve their…

    1 条评论
  • How to handle missing data in Machine Learning Project

    How to handle missing data in Machine Learning Project

    Handling missing data for any machine learning project is very crucial step. It is first step of EDA(exploratory data…

  • Buid Chatbot Using RASA Framework

    Buid Chatbot Using RASA Framework

    RASA framework is one of famous python based open source platform for building the chatbot. What is the Chatbot Chatbot…

  • Retraining Automation in Chatbot Projects

    Retraining Automation in Chatbot Projects

    For any machine learning/NLP projects Data cleaning and retraining is a key aspect. In most of the chatbot projects…

  • AI behind the Smart Replies and Language Translation Service ..

    AI behind the Smart Replies and Language Translation Service ..

    Now a days , we can see lot of autogenerated smart reply options come on google/linkedin like below. Also , most of us…

  • Natural Language Processing Steps

    Natural Language Processing Steps

    Natural Language Processing allows computer to break down and interpret natural language spoken by human. NLP is the…

  • Difference between Stemmer and Lemmatization in NLP

    Difference between Stemmer and Lemmatization in NLP

    Natural language processing is one of the important field in machine learning and data science. NLP is used for…

  • Things to remember before building chatbot

    Things to remember before building chatbot

    We should remember below points while developing chatbot : 1) Channel Integration : Sometimes there is a ask to…

    3 条评论

社区洞察

其他会员也浏览了