ciq_rag_gradio / src /streamlit_app.py
khushininebit's picture
Update src/streamlit_app.py
11c3562 verified
import gradio as gr
from ninebit_ciq import NineBitCIQClient
# Initialize CIQ client with API key (replace with your own or use gr.Textbox)
ciq_client = NineBitCIQClient(api_key="28a8c113-5184-4532-ac52-b3be164b95e1")
pdf_ingested = {"status": False}
def ingest_pdf(file):
if file is None:
return "Please upload a PDF first."
result = ciq_client.ingest_file(file=file.name)
pdf_ingested["status"] = True
return "โœ… PDF ingested successfully!"
def ask_question(query):
if not pdf_ingested["status"]:
return "โš ๏ธ Please upload and ingest a PDF first."
response = ciq_client.rag_query(query=query)
return response
with gr.Blocks() as demo:
gr.Markdown("## ๐Ÿ“„ CIQ PDF Chatbot")
gr.Markdown("Upload a PDF, ask a question, and get answers using NineBit CIQ RAG")
with gr.Row():
pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"])
upload_btn = gr.Button("Ingest PDF")
upload_output = gr.Textbox(label="Ingestion Status")
upload_btn.click(fn=ingest_pdf, inputs=pdf_input, outputs=upload_output)
with gr.Row():
query_input = gr.Textbox(label="Ask a Question")
query_btn = gr.Button("Submit Query")
answer_output = gr.Textbox(label="RAG Answer")
query_btn.click(fn=ask_question, inputs=query_input, outputs=answer_output)
demo.launch()