gijl commited on
Commit
b386df6
·
verified ·
1 Parent(s): e32e378

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -6
main.py CHANGED
@@ -10,23 +10,25 @@ app = FastAPI()
10
 
11
  model_id = "gijl/gemma-4-E4B-it"
12
 
13
- # تحميل المعالج والنموذج
14
- print("جاري تحميل النموذج...")
15
- processor = AutoProcessor.from_pretrained(model_id)
 
 
16
  model = AutoModelForImageTextToText.from_pretrained(
17
  model_id,
18
  torch_dtype=torch.bfloat16,
19
  low_cpu_mem_usage=True,
20
- device_map="auto"
 
21
  )
 
22
 
23
- # عرض واجهة React عند الدخول للموقع
24
  @app.get("/")
25
  async def read_index():
26
  with open("index.html", "r", encoding="utf-8") as f:
27
  return HTMLResponse(content=f.read())
28
 
29
- # نقطة النهاية (Endpoint) لاستقبال الصورة والنص وإرجاع النتيجة
30
  @app.post("/generate")
31
  async def generate_text(image: UploadFile = File(...), text: str = Form(...)):
32
  try:
 
10
 
11
  model_id = "gijl/gemma-4-E4B-it"
12
 
13
+ # --- السطر 13: استبدال الجزء القديم بهذا الجزء الجديد ---
14
+ print("جاري تحميل المعالج...")
15
+ processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
16
+
17
+ print("جاري تحميل النموذج (قد يستغرق وقتاً بسبب الحجم)...")
18
  model = AutoModelForImageTextToText.from_pretrained(
19
  model_id,
20
  torch_dtype=torch.bfloat16,
21
  low_cpu_mem_usage=True,
22
+ device_map="auto",
23
+ trust_remote_code=True
24
  )
25
+ # -------------------------------------------------------
26
 
 
27
  @app.get("/")
28
  async def read_index():
29
  with open("index.html", "r", encoding="utf-8") as f:
30
  return HTMLResponse(content=f.read())
31
 
 
32
  @app.post("/generate")
33
  async def generate_text(image: UploadFile = File(...), text: str = Form(...)):
34
  try: