DEV Community

parmarjatin4911@gmail.com
parmarjatin4911@gmail.com

Posted on

Llama Index + Supabase + Gradio

Llama Index + Supabase + Gradio

import os
import gradio as gr
from llama_index import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores import SupabaseVectorStore

Set up environment variable and data

os.environ['OPENAI_API_KEY'] = "[your_openai_api_key]"

documents = SimpleDirectoryReader('data').load_data()
index = VectorStoreIndex.from_documents(documents)
index.storage_context.persist()

DB_PASSWORD = os.environ['DB_PASSWORD']
DB_CONNECTION = f"postgresql://postgres:{DB_PASSWORD}@localhost:5431/db"

vector_store = SupabaseVectorStore(
postgres_connection_string=DB_CONNECTION,
collection_name='base_demo'
)

query_engine = index.as_query_engine()

def main(question):
response = query_engine.query(question)
return response

Gradio interface

ui = gr.Interface(
fn=main,
inputs=gr.inputs.Textbox(placeholder="Enter your question about the author..."),
outputs=gr.outputs.Textbox()
)
ui.launch()

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay