File size: 1,306 Bytes
f2afc8d ab69918 3cf3cc6 cd8cf32 f2afc8d 3cf3cc6 ab69918 f2afc8d 3cf3cc6 95835e2 3cf3cc6 cd8cf32 3cf3cc6 ab69918 f2afc8d ab69918 f2afc8d 049312f b384ec1 ab69918 41cf145 049312f ec3b1e1 d43c0b9 f2afc8d ab69918 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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() |