Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ninebit_ciq import NineBitCIQClient
|
| 3 |
+
|
| 4 |
+
# Initialize CIQ client with API key (replace with your own or use gr.Textbox)
|
| 5 |
+
ciq_client = NineBitCIQClient(api_key="28a8c113-5184-4532-ac52-b3be164b95e1")
|
| 6 |
+
|
| 7 |
+
pdf_ingested = {"status": False}
|
| 8 |
+
|
| 9 |
+
def ingest_pdf(file):
|
| 10 |
+
if file is None:
|
| 11 |
+
return "Please upload a PDF first."
|
| 12 |
+
result = ciq_client.ingest_file(file=file.name)
|
| 13 |
+
pdf_ingested["status"] = True
|
| 14 |
+
return "✅ PDF ingested successfully!"
|
| 15 |
+
|
| 16 |
+
def ask_question(query):
|
| 17 |
+
if not pdf_ingested["status"]:
|
| 18 |
+
return "⚠️ Please upload and ingest a PDF first."
|
| 19 |
+
response = ciq_client.rag_query(query=query)
|
| 20 |
+
return response
|
| 21 |
+
|
| 22 |
+
with gr.Blocks() as demo:
|
| 23 |
+
gr.Markdown("## 📄 CIQ PDF Chatbot")
|
| 24 |
+
gr.Markdown("Upload a PDF, ask a question, and get answers using NineBit CIQ RAG")
|
| 25 |
+
|
| 26 |
+
with gr.Row():
|
| 27 |
+
pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"])
|
| 28 |
+
upload_btn = gr.Button("Ingest PDF")
|
| 29 |
+
|
| 30 |
+
upload_output = gr.Textbox(label="Ingestion Status")
|
| 31 |
+
|
| 32 |
+
upload_btn.click(fn=ingest_pdf, inputs=pdf_input, outputs=upload_output)
|
| 33 |
+
|
| 34 |
+
with gr.Row():
|
| 35 |
+
query_input = gr.Textbox(label="Ask a Question")
|
| 36 |
+
query_btn = gr.Button("Submit Query")
|
| 37 |
+
|
| 38 |
+
answer_output = gr.Textbox(label="RAG Answer")
|
| 39 |
+
|
| 40 |
+
query_btn.click(fn=ask_question, inputs=query_input, outputs=answer_output)
|
| 41 |
+
|
| 42 |
+
demo.launch()
|