Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -6,8 +6,8 @@ from sentence_transformers import SentenceTransformer
|
|
6 |
import json
|
7 |
from dspy import Example, MIPROv2, Evaluate, evaluate
|
8 |
|
9 |
-
# إعداد LLM
|
10 |
-
dspy.settings.configure(lm=dspy.
|
11 |
|
12 |
# إعداد قاعدة البيانات
|
13 |
client = chromadb.Client(Settings(chroma_db_impl="duckdb+parquet", persist_directory="./chroma_db"))
|
@@ -15,7 +15,6 @@ col = client.get_or_create_collection(name="arabic_docs", metadata={"hnsw:space"
|
|
15 |
|
16 |
embedder = SentenceTransformer("sentence-transformers/LaBSE")
|
17 |
|
18 |
-
# استيراد وتقطيع PDF
|
19 |
def process_pdf(pdf_bytes):
|
20 |
doc = fitz.open(stream=pdf_bytes, filetype="pdf")
|
21 |
texts = []
|
@@ -60,7 +59,7 @@ def load_dataset(path):
|
|
60 |
return [Example(**json.loads(l)).with_inputs("question") for l in f]
|
61 |
|
62 |
def optimize(train_file, val_file):
|
63 |
-
global model
|
64 |
trainset = load_dataset(train_file.name)
|
65 |
valset = load_dataset(val_file.name)
|
66 |
tp = MIPROv2(metric=evaluate.answer_exact_match, auto="light", num_threads=4)
|
@@ -69,7 +68,7 @@ def optimize(train_file, val_file):
|
|
69 |
return "✅ تم تحسين النموذج!"
|
70 |
|
71 |
with gr.Blocks() as demo:
|
72 |
-
gr.Markdown("## 🧠 نظام RAG عربي باستخدام DSPy")
|
73 |
with gr.Tab("📥 تحميل وتخزين"):
|
74 |
pdf_input = gr.File(label="ارفع ملف PDF")
|
75 |
ingest_btn = gr.Button("إضافة إلى قاعدة البيانات")
|
@@ -86,4 +85,3 @@ with gr.Blocks() as demo:
|
|
86 |
result = gr.Textbox(label="نتيجة التحسين")
|
87 |
opt_btn.click(optimize, inputs=[train_file, val_file], outputs=result)
|
88 |
demo.launch()
|
89 |
-
|
|
|
6 |
import json
|
7 |
from dspy import Example, MIPROv2, Evaluate, evaluate
|
8 |
|
9 |
+
# ✅ إعداد LLM مفتوح المصدر من Hugging Face
|
10 |
+
dspy.settings.configure(lm=dspy.HFModel("NousResearch/Hermes-2-Pro-Mistral-7B", max_tokens=1024))
|
11 |
|
12 |
# إعداد قاعدة البيانات
|
13 |
client = chromadb.Client(Settings(chroma_db_impl="duckdb+parquet", persist_directory="./chroma_db"))
|
|
|
15 |
|
16 |
embedder = SentenceTransformer("sentence-transformers/LaBSE")
|
17 |
|
|
|
18 |
def process_pdf(pdf_bytes):
|
19 |
doc = fitz.open(stream=pdf_bytes, filetype="pdf")
|
20 |
texts = []
|
|
|
59 |
return [Example(**json.loads(l)).with_inputs("question") for l in f]
|
60 |
|
61 |
def optimize(train_file, val_file):
|
62 |
+
global model
|
63 |
trainset = load_dataset(train_file.name)
|
64 |
valset = load_dataset(val_file.name)
|
65 |
tp = MIPROv2(metric=evaluate.answer_exact_match, auto="light", num_threads=4)
|
|
|
68 |
return "✅ تم تحسين النموذج!"
|
69 |
|
70 |
with gr.Blocks() as demo:
|
71 |
+
gr.Markdown("## 🧠 نظام RAG عربي باستخدام DSPy + نموذج مفتوح المصدر")
|
72 |
with gr.Tab("📥 تحميل وتخزين"):
|
73 |
pdf_input = gr.File(label="ارفع ملف PDF")
|
74 |
ingest_btn = gr.Button("إضافة إلى قاعدة البيانات")
|
|
|
85 |
result = gr.Textbox(label="نتيجة التحسين")
|
86 |
opt_btn.click(optimize, inputs=[train_file, val_file], outputs=result)
|
87 |
demo.launch()
|
|