Spaces:
Running
Running
Commit History
-
Update app.py Running
Verified signature451bc89 -
Update app.py
Verified signatureimport requests def hf_free_inference(model, prompt): response = requests.post( f"https://router.huggingface.co/hf-inference/models/{model}", headers={"Authorization": f"Bearer {HF_TOKEN}"}, json={"inputs": prompt} ) data = response.json() # Some models return a list, others return a dict if isinstance(data, list) and "generated_text" in data[0]: return data[0]["generated_text"] if isinstance(data, dict) and "generated_text" in data: return data["generated_text"] return str(data)165947a -
Update app.py
Verified signature8ea8fe8
-
Update app.py
Verified signatureQwen/Qwen2.5-14B-Instruct38a2b8e -
Update app.py
Verified signatureQwen2.5‑14B‑Instructc4145a0 -
Update app.py
Verified signatureAdd memory contextdc063ef -
Update app.py
Verified signature0135e8c -
Update app.py
Verified signaturedef retrieve_context(question, state, k=15)be89ea1 -
Update app.py
Verified signaturedef remove_pdf(filename, state): if filename not in state["files"]: return ( f"{filename} not found.", state, gr.update(choices=list(state["files"].keys()), value=None) ) # Remove the file entry state["files"].pop(filename, None) # Rebuild chunks from remaining files all_chunks = [] for chunks in state["files"].values(): all_chunks.extend(chunks) state["chunks"] = all_chunks state["pdf_count"] = len(state["files"]) if state["chunks"]: index, _ = build_vectorstore(state["chunks"]) state["index"] = index else: state["index"] = None return ( f"Removed {filename}. Total chunks: {len(state['chunks'])}", state, gr.update(choices=list(state["files"].keys()), value=None) )5f6a59c -
Update app.py
Verified signature180b29c -
Update app.py
Verified signaturedef load_pdf(files, state): if not files: return "No file uploaded.", state, list(state["files"].keys()) try: # Deduplicate by file path unique_files = list({f['name']: f for f in files}.values()) for file in unique_files: filename = os.path.basename(file['name']) # FIX text = read_pdf(file['name']) new_chunks = chunk_text(text) if not new_chunks: continue state["files"][filename] = new_chunks state["chunks"].extend(new_chunks) state["pdf_count"] += 1 index, _ = build_vectorstore(state["chunks"]) state["index"] = index return ( f"{state['pdf_count']} PDF(s) loaded. Total chunks: {len(state['chunks'])}", state, list(state["files"].keys()) # FIX: now contains real filenames ) except Exception as e: return ( f"Error processing PDF: {e}", s…5299745 -
Update app.py
Verified signaturedef load_pdf(files, state): if not files: return "No file uploaded.", state, list(state["files"].keys()) try: for file in files: filename = os.path.basename(file) # <-- FIX text = read_pdf(file) new_chunks = chunk_text(text) if not new_chunks: continue state["files"][filename] = new_chunks state["chunks"].extend(new_chunks) state["pdf_count"] += 1 index, _ = build_vectorstore(state["chunks"]) state["index"] = index return ( f"{state['pdf_count']} PDF(s) loaded. Total chunks: {len(state['chunks'])}", state, list(state["files"].keys()) # <-- now contains real filenames ) except Exception as e: return ( f"Error processing PDF: {e}", state, list(state["files"].keys()) )7996c23 -
Update app.py
Verified signaturedd12c0c -
Update app.py
Verified signaturedef load_pdf(files, state): if not files: return "No file uploaded.", state, list(state["files"].keys()) try: for file in files: filename = file.name text = read_pdf(file) new_chunks = chunk_text(text) if not new_chunks: continue # Save chunks for this file state["files"][filename] = new_chunks # Add to global chunk list state["chunks"].extend(new_chunks) state["pdf_count"] += 1 # Rebuild FAISS index, _ = build_vectorstore(state["chunks"]) state["index"] = index return ( f"{state['pdf_count']} PDF(s) loaded. Total chunks: {len(state['chunks'])}", state, list(state["files"].keys()) ) except Exception as e: return ( f"Error processing PDF: {e}", state, list(state["files"].keys()) )8051cd5 -
Update app.py
Verified signaturedef remove_pdf(filename, state): if filename not in state["files"]: return f"{filename} not found.", state, list(state["files"].keys()) # Remove its chunks chunks_to_remove = state["files"].pop(filename) # Remove from global chunk list state["chunks"] = [c for c in state["chunks"] if c not in chunks_to_remove] # Rebuild FAISS if state["chunks"]: index, _ = build_vectorstore(state["chunks"]) state["index"] = index else: state["index"] = None state["pdf_count"] -= 1 return ( f"Removed {filename}. Total chunks: {len(state['chunks'])}", state, list(state["files"].keys()) )765eae2 -
Update app.py
Verified signature# Bind events AFTER components exist pdf_input.upload( load_pdf, inputs=[pdf_input, state], outputs=[pdf_status, state, file_selector] ) remove_button.click( remove_pdf, inputs=[file_selector, state], outputs=[pdf_status, state, file_selector] ) ask_button.click( answer_question, inputs=[question, state], outputs=answer ) clear_button.click(lambda: "", outputs=question) if __name__ == "__main__": demo.launch( css=".clear-btn button { height: 100%; min-height: 52px; }" )340d4e8 -
Update app.py
Verified signature2c7e565 -
Update app.py
Verified signature40024c6 -
Update app.py
Verified signature64afd4a -
Update app.py
Verified signaturewith gr.Blocks( title="PDF Q&A Chatbot", css=".clear-btn button { height: 100%; }" ) as demo: gr.Markdown("## 📄 PDF Q&A Chatbot\nUpload a PDF and ask questions about its content.") state = gr.State({"chunks": [], "index": None, 'pdf_count':0}) with gr.Row(): with gr.Column(scale=1): pdf_input = gr.File(label="Upload PDF(s)", file_types=[".pdf"], multiple=True) pdf_status = gr.Textbox(label="Status", interactive=False) with gr.Column(scale=2): with gr.Row(): question = gr.Textbox(label="Your question", lines=2, scale =3) clear_button = gr.Button("Clear", scale=1, min_width=80, elem_classes="clear-btn") answer = gr.Textbox(label="Answer", lines=8) ask_button = gr.Button("Ask") pdf_input.upload(load_pdf, inputs=[pdf_input, state], outputs=[pdf_status, state]) ask_button.click(answer_question, inputs=[questio…bbe2a51 -
Update app.py
Verified signaturewith gr.Column(scale=2): with gr.Row():8594f0e -
Update app.py
Verified signaturewith gr.Column(scale=2): with gr.row():3308433 -
Update app.py
Verified signaturestate = gr.State({"chunks": [], "index": None, 'pdf_count':0}) with gr.Row(): with gr.Column(scale=1): pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"]) pdf_status = gr.Textbox(label="Status", interactive=False) with gr.Column(scale=2): with gr.row() question = gr.Textbox(label="Your question", lines=2) clear_button = gr.Button("Clear Question") answer = gr.Textbox(label="Answer", lines=8) ask_button = gr.Button("Ask")6fbbf95 -
Update app.py
Verified signatureLLM_MODEL = "deepseek-ai/DeepSeek-V3"838ec48 -
Update app.py
Verified signatureLLM_MODEL = 'deepseek-ai/DeepSeek-V3-Chat'd611121 -
Update app.py
Verified signature261bc23 -
Update app.py
Verified signaturemeta-llama/Llama-3.1-8B-Instructf5cd3d7 -
Update app.py
Verified signatureprint("HF_TOKEN loaded:", HF_TOKEN is not None) if HF_TOKEN: print("HF_TOKEN length:", len(HF_TOKEN)) print("HF_TOKEN preview:", HF_TOKEN[:6] + "..." + HF_TOKEN[-4:]) else: print("HF_TOKEN is None or empty")0cbbe57 -
Update app.py
Verified signatureHF_TOKEN = os.getenv("HF_TOKEN", None)9766920 -
Update app.py
Verified signatureprint("HF_TOKEN_2 loaded:", HF_TOKEN is not None)9d0a74f -
Update app.py
Verified signatureHF_TOKEN = os.getenv("HF_TOKEN_2", None)fd48d96 -
Update app.py
Verified signatureLLM_MODEL = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"670a0a9 -
Update app.py
Verified signatureabdbf09 -
Update app.py
Verified signatureremove concurency7f73068 -
Update app.py
Verified signaturedemo.queue(max_size=32, concurrency=1)f66ee69 -
Update app.py
Verified signature# Limit concurrency (HF-compatible) demo.queue(concurrency_count=1)10205ee -
Update app.py
Verified signature✔ No more crashes from 429 The retry logic absorbs rate limits gracefully. ✔ Gradio won’t spawn multiple parallel LLM calls concurrency_limit=1 prevents overload.f3aa49e
-
Update requirements.txt
Verified signature388ea77 -
Update requirements.txt
Verified signatureremove: --upgrade-strategy eager2ef14c9 -
Update requirements.txt
Verified signature19676a9 -
Update requirements.txt
Verified signaturetorch==2.5.18a3fbbc -
Update requirements.txt
Verified signature# --- Utilities --- pydantic==2.10.6 langchain-text-splitters==0.3.0 sentencepiece==0.1.99 protobuf==4.25.3 PyPDF2==3.0.1 huggingface_hub==0.25.2 requests==2.31.0 numpy==1.26.4 torch==2.1.202e563a -
Update requirements.txt
Verified signaturefaiss-cpu==1.13.2790db37 -
Update requirements.txt
Verified signaturePyPDF2==3.0.1 huggingface_hub==0.23.0 requests==2.31.0fb8e56a -
Update app.py
Verified signatureresponse = llm.chat.completions.create( model=LLM_MODEL, messages=[{"role": "user", "content": prompt}], max_tokens=2048, temperature=0.25, top_p=0.9, frequency_penalty=0.1, # reduces repetition presence_penalty=0.0 # keeps answers grounded )8464ccf -
Update app.py
Verified signatureLLM_MODEL = "deepseek-ai/DeepSeek-R1-Distill-Qwen-14B"1a03e36 -
Update app.py
Verified signatureLLM_MODEL = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"94034e1 -
Update app.py
Verified signatureLLM_MODEL = "DeepSeek‑R1‑Distill‑Qwen‑7B"04a11e4 -
Update app.py
Verified signatureLLM_MODEL = "meta-llama/Llama-3.2-8B-Instruct"70f2013 -
Update app.py
Verified signatureLLM_MODEL = "meta-llama/Llama-3.1-8B-Instruct"56a2e0e