Find answers from the community

s
F
Y
a
P
Updated last year

Hey I wanted to share that my peer just

Hey I wanted to share that my peer just shared a basic llama-index use case using gradio to provide the UI and ... I have never used gradio before and I was very impressed how easy it was. The whole ui for the chatbot is just a couple lines of code:
Plain Text
iface = gr.Interface(fn=chatbot,
                     inputs=gr.inputs.Textbox(lines=7, label="How may I help you?"),
                     outputs="text",
                     title="Tanzu-Trained-ChatBot")

So simple, I will make a thread and paste the full code, but its just the basic llamaindex pattern + these couple lines and you get a nice gui!
a
L
A
3 comments
Here is the full code for reference, note that it still needs to be updated to use the new GPTSimpleVector store naming conventions:
Plain Text
from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
from langchain.chat_models import ChatOpenAI
import gradio as gr
import sys
import os
os.environ["OPENAI_API_KEY"] = 'secret api key here' #Mike's key

def construct_index(directory_path):
    max_input_size = 4096
    num_outputs = 512
    max_chunk_overlap = 20
    chunk_size_limit = 600

    prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)

    llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_outputs))

    documents = SimpleDirectoryReader(directory_path).load_data()

    index = GPTSimpleVectorIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)

    index.save_to_disk('index.json')

    return index

def chatbot(input_text):
    index = GPTSimpleVectorIndex.load_from_disk('index.json')
    response = index.query(input_text, response_mode="compact")
    return response.response

iface = gr.Interface(fn=chatbot,
                     inputs=gr.inputs.Textbox(lines=7, label="How may I help you?"),
                     outputs="text",
                     title="Tanzu-Trained-ChatBot")

index = construct_index("docs")
iface.launch(share=False, server_name="0.0.0.0", server_port=8080)
Very cool!

gradio is great for constructing a quick frontend for your apps/demos πŸ’ͺπŸ’ͺ
Add a reply
Sign up and join the conversation on Discord