dtuckchat / app.py
Unizomby's picture
Update app.py
95835e2 verified
raw
history blame
1.31 kB
import gradio as gr
import os
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, Settings
from llama_index.llms.openai import OpenAI
# Set OpenAI API key from environment
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
# Configure the default LLM
Settings.llm = OpenAI(model="gpt-4.1-nano")
# Load documents and build index
documents = SimpleDirectoryReader("documents").load_data()
index = VectorStoreIndex.from_documents(documents)
# Create query engine
query_engine = index.as_query_engine()
def chatbot_response(message):
response = query_engine.query(message)
return str(response)
# # Create a custom theme with a blue background
# custom_theme = gr.themes.Default(primary_hue=colors.blue).set(
# body_background_fill="#fafaff"
# )
iface = gr.Interface(fn=chatbot_response,
inputs="text",
outputs="text",
title="Ask about me",
description="Ask questions and receive answers based on my bio.",
# theme=custom_theme,
examples=[["Provide a summary of Donald?"],
["Has Donald worked with Python?"],
["Tell me something interesting about Donald"]]
)
iface.launch()