Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,47 +0,0 @@
|
|
| 1 |
-
# app.py (repo root)
|
| 2 |
-
import os
|
| 3 |
-
import sys
|
| 4 |
-
import gradio as gr
|
| 5 |
-
|
| 6 |
-
# day3 qovluğunu import yoluna əlavə edək
|
| 7 |
-
sys.path.append(os.path.join(os.path.dirname(__file__), "day3"))
|
| 8 |
-
|
| 9 |
-
from rag_system import RAGPipeline
|
| 10 |
-
|
| 11 |
-
# Hugging Face Space üçün ayrıca persist directory
|
| 12 |
-
rag = RAGPipeline(persist_dir="./chroma_db_space", collection_name="pdf_docs")
|
| 13 |
-
|
| 14 |
-
def chat_with_pdf(pdf_path: str, question: str) -> str:
|
| 15 |
-
"""
|
| 16 |
-
pdf_path: Gradio File input (type="filepath") tam fayl yolunu verir.
|
| 17 |
-
question: İstifadəçi sualı.
|
| 18 |
-
"""
|
| 19 |
-
if not pdf_path:
|
| 20 |
-
return "Zəhmət olmasa PDF yüklə."
|
| 21 |
-
if not question or not question.strip():
|
| 22 |
-
return "Zəhmət olmasa sual daxil et."
|
| 23 |
-
|
| 24 |
-
# PDF-i indekslə (Chroma-ya yaz) və cavabı al
|
| 25 |
-
try:
|
| 26 |
-
rag.index_document(pdf_path, doc_id_prefix="upload")
|
| 27 |
-
out = rag.query(question, k=4)
|
| 28 |
-
return out["answer"]
|
| 29 |
-
except Exception as e:
|
| 30 |
-
return f"Xəta baş verdi: {e}"
|
| 31 |
-
|
| 32 |
-
demo = gr.Interface(
|
| 33 |
-
fn=chat_with_pdf,
|
| 34 |
-
inputs=[
|
| 35 |
-
# Vacib: type="filepath" → sadə string path qaytarır (Spaces-də schema problemi olmur)
|
| 36 |
-
gr.File(label="PDF yüklə", file_types=[".pdf"], type="filepath"),
|
| 37 |
-
gr.Textbox(label="Sual ver", placeholder="PDF nə deyir?")
|
| 38 |
-
],
|
| 39 |
-
outputs=gr.Textbox(label="Cavab"),
|
| 40 |
-
title="PDF RAG (Chroma + Groq)",
|
| 41 |
-
description="PDF yüklə və sual ver. Chroma ilə retrieval, Groq LLM ilə cavab."
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
# Spaces-də launch çağırmırıq; yalnız lokal test üçün:
|
| 45 |
-
if __name__ == "__main__" and os.getenv("SPACE_ID") is None:
|
| 46 |
-
# Lokal işlədərkən bu xətti aktivdir
|
| 47 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|