Uunan commited on
Commit
3645e2a
·
verified ·
1 Parent(s): 01846e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -1,8 +1,14 @@
 
1
  import torch
2
  from PIL import Image
3
  from transformers import Blip2Processor, Blip2ForConditionalGeneration
4
  import gradio as gr
5
 
 
 
 
 
 
6
  # ---------------------------------------------------------
7
  # DEVICE
8
  # ---------------------------------------------------------
@@ -15,10 +21,16 @@ print(f"🚀 Device: {device} | dtype: {dtype}")
15
  # MODEL
16
  # ---------------------------------------------------------
17
  MODEL_NAME = "Salesforce/blip2-flan-t5-xl"
 
 
18
 
19
  print("⏳ Model yükleniyor...")
20
 
21
- processor = Blip2Processor.from_pretrained(MODEL_NAME)
 
 
 
 
22
  model = Blip2ForConditionalGeneration.from_pretrained(
23
  MODEL_NAME,
24
  torch_dtype=dtype,
@@ -55,14 +67,19 @@ def generate_caption(image: Image.Image):
55
  return caption
56
 
57
  # ---------------------------------------------------------
58
- # GRADIO UI
59
  # ---------------------------------------------------------
60
  demo = gr.Interface(
61
  fn=generate_caption,
62
  inputs=gr.Image(type="pil", label="📷 Görsel Yükle"),
63
  outputs=gr.Textbox(label="📝 Üretilen Açıklama"),
 
64
  title="BLIP-2 Image Captioning",
65
- description="BLIP-2 FLAN-T5-XL ile fotoğraftan metin üretme (GPU)"
66
  )
67
 
68
- demo.launch()
 
 
 
 
 
1
+ import os
2
  import torch
3
  from PIL import Image
4
  from transformers import Blip2Processor, Blip2ForConditionalGeneration
5
  import gradio as gr
6
 
7
+ # ---------------------------------------------------------
8
+ # ENV FIX (OPSİYONEL AMA TEMİZ)
9
+ # ---------------------------------------------------------
10
+ os.environ["OMP_NUM_THREADS"] = "1"
11
+
12
  # ---------------------------------------------------------
13
  # DEVICE
14
  # ---------------------------------------------------------
 
21
  # MODEL
22
  # ---------------------------------------------------------
23
  MODEL_NAME = "Salesforce/blip2-flan-t5-xl"
24
+ # Space çok çöküyorsa şuna düş:
25
+ # MODEL_NAME = "Salesforce/blip2-flan-t5-base"
26
 
27
  print("⏳ Model yükleniyor...")
28
 
29
+ processor = Blip2Processor.from_pretrained(
30
+ MODEL_NAME,
31
+ use_fast=True
32
+ )
33
+
34
  model = Blip2ForConditionalGeneration.from_pretrained(
35
  MODEL_NAME,
36
  torch_dtype=dtype,
 
67
  return caption
68
 
69
  # ---------------------------------------------------------
70
+ # GRADIO UI + API
71
  # ---------------------------------------------------------
72
  demo = gr.Interface(
73
  fn=generate_caption,
74
  inputs=gr.Image(type="pil", label="📷 Görsel Yükle"),
75
  outputs=gr.Textbox(label="📝 Üretilen Açıklama"),
76
+ api_name="generate_caption", # 🔴 API İSMİ
77
  title="BLIP-2 Image Captioning",
78
+ description="BLIP-2 FLAN-T5 ile Image Text"
79
  )
80
 
81
+ demo.launch(
82
+ server_name="0.0.0.0",
83
+ server_port=7860,
84
+ show_error=True
85
+ )