0Pricing
MLOps Academy · درس

نقطة النهاية /predict الأولى

حمّل نموذجاً وأعد تنبؤاً عبر HTTP.

نقطة النهاية /predict الأولى درس مجاني في MLOps Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في MLOps Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة MLOps Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

From Notebook to API

A model in a notebook helps only you. To serve real users, you wrap it in an API that anyone can call over the network. 🚀

Why FastAPI

FastAPI is a modern Python web framework that is fast to write, validates input for you, and auto-generates interactive docs.

Install It

You need two pieces: FastAPI itself and a server to run it. Install both with pip in one line.

pip install fastapi uvicorn

Create the App

Everything starts from one app object. You create a FastAPI instance and attach routes to it.

from fastapi import FastAPI

app = FastAPI()

What an Endpoint Is

An endpoint is a URL your app responds to, like /predict. Each one runs a Python function when someone calls it.

Load Your Model First

Before predicting, you load the trained model from disk. Here joblib reads a saved scikit-learn model into memory.

import joblib

model = joblib.load("model.joblib")

Declare the Route

You mark a function as a POST endpoint with a decorator. POST fits prediction because you send data in the request body.

@app.post("/predict")
def predict(features: list[float]):
    ...

Run the Prediction

Inside the function you call the model. predict expects a 2D input, so you wrap the row in a list before passing it.

pred = model.predict([features])
result = pred[0]

Return JSON

Whatever your function returns, FastAPI serializes to JSON automatically. Return a plain dict and the client gets clean JSON.

return {"prediction": result}

Start the Server

You launch the app with uvicorn, pointing it at the module and the app object. The reload flag restarts on code changes.

uvicorn main:app --reload

Try the Auto Docs

Visit /docs in your browser and FastAPI shows an interactive page where you can test /predict without writing any client code. 🎉

Quick Check

You want clients to send feature data to your model. Which HTTP method fits a /predict endpoint?

Recap

You wrapped a model in FastAPI: create the app, load the model, expose a POST /predict that returns JSON, and run it with uvicorn. That is a live API! 🙌

الأسئلة الشائعة

هل درس «نقطة النهاية /predict الأولى» مجاني؟

نعم — نص درس «نقطة النهاية /predict الأولى» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة MLOps Academy، انتقل إلى CoddyKit PRO. تتضمن دورة MLOps Academy 4 دروس في المجموع.

ماذا ستتعلم في «نقطة النهاية /predict الأولى»؟

حمّل نموذجاً وأعد تنبؤاً عبر HTTP. تتمرن على MLOps Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ MLOps Academy؟

لا تُشترط خبرة سابقة. MLOps Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «نقطة النهاية /predict الأولى»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس MLOps Academy هذا؟

نعم. كل درس في MLOps Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. نقطة النهاية /predict الأولى
  2. التحقق من الطلبات باستخدام Pydantic
  3. تحميل النموذج مرة واحدة عند بدء التشغيل
  4. إضافة فحص الجاهزية /health
← العودة إلى MLOps Academy