Spaces:
Running
Running
File size: 1,435 Bytes
a12ab13 01784fc a12ab13 01784fc a12ab13 01784fc a12ab13 01784fc a12ab13 01784fc a12ab13 01784fc a12ab13 01784fc a12ab13 01784fc a12ab13 01784fc a12ab13 3bd8ac9 6472aa7 a12ab13 6472aa7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# app.py
import onnxruntime as ort
from embeddingonnx import text_to_embedding, query_to_embedding
import gradio as gr
# ==============================
# دالة سريعة للتحويل (Gradio)
# ==============================
def embed_text(text: str):
if not text.strip():
return "❌ النص فارغ"
vec = text_to_embedding(text.strip())
return vec.tolist()
def query_text(text: str):
if not text.strip():
return "❌ النص فارغ"
vec = query_to_embedding(text.strip())
return vec.tolist()
# ==============================
# واجهة Gradio بسيطة
# ==============================
with gr.Blocks() as demo:
gr.Markdown("## Arabic Text Embedding API (Local)")
with gr.Row():
text_input = gr.Textbox(label="النص", placeholder="أدخل نص عربي...")
text_output = gr.Textbox(label="Embedding")
text_input.submit(embed_text, text_input, text_output)
with gr.Row():
query_input = gr.Textbox(label="Query", placeholder="أدخل نص البحث...")
query_output = gr.Textbox(label="Query Embedding")
query_input.submit(query_text, query_input, query_output)
# ==============================
# تشغيل محلي
# ==============================
# ==============================
# تشغيل محلي مع رابط
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)
|