Spaces:
Runtime error
Runtime error
| 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] | |
| 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="/") |