File size: 1,055 Bytes
26485e3
411fb9c
 
 
 
26485e3
411fb9c
 
26485e3
 
411fb9c
 
 
 
 
 
26485e3
 
 
 
411fb9c
 
 
 
 
daa3a46
411fb9c
26485e3
 
 
 
411fb9c
26485e3
 
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
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from sentence_transformers import SentenceTransformer
import gradio as gr

# تحميل الموديل
model = SentenceTransformer("paraphrase-multilingual-MiniLM-L12-v2")

# -------- FastAPI (الخدمة التي تهمك) --------
api = FastAPI()

class EmbedRequest(BaseModel):
    texts: list[str]

@api.post("/embed")
def embed(req: EmbedRequest):
    if not req.texts:
        return {"embeddings": []}
    
    # تحويل النصوص إلى Vector
    embeddings = model.encode(
        req.texts,
        convert_to_numpy=True,
        normalize_embeddings=True
    )
    return {"embeddings": embeddings.tolist()}

# -------- Gradio (مجرد غطاء لإرضاء المنصة) --------
# سننشئ واجهة فارغة تقريباً لا تستهلك أي موارد
with gr.Blocks() as demo:
    gr.Markdown("### Embedding API Service is Running")

# ربط FastAPI بـ Gradio ليعمل على نفس المنفذ
app = gr.mount_gradio_app(api, demo, path="/")