Spaces:
Runtime error
Runtime error
| 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() | |