pranav3108 commited on
Commit
dcb2e77
·
verified ·
1 Parent(s): 9a5bc65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -15,15 +15,14 @@ import pickle
15
  from PIL import Image
16
 
17
  # ================================
18
- # LOAD FUSION MODEL (CRITICAL FIX)
19
  # ================================
20
  fusion_model = tf.keras.models.load_model(
21
- "fusion_ticket_model.h5",
22
- compile=False,
23
- safe_mode=False # 🔥 REQUIRED FOR MULTI-INPUT MODELS
24
  )
25
 
26
- print("✅ Fusion model loaded")
27
 
28
  # ================================
29
  # LOAD TOKENIZER
@@ -46,7 +45,7 @@ LABELS = ["Critical", "High", "Medium", "Low"]
46
  def preprocess_image(image: Image.Image):
47
  image = image.convert("RGB")
48
  image = image.resize(IMG_SIZE)
49
- img = np.array(image, dtype=np.float32) / 255.0
50
  img = np.expand_dims(img, axis=0)
51
  return img
52
 
@@ -54,7 +53,7 @@ def preprocess_image(image: Image.Image):
54
  # TEXT PREPROCESSING
55
  # ================================
56
  def preprocess_text(text: str):
57
- if text is None:
58
  text = ""
59
  seq = tokenizer.texts_to_sequences([text])
60
  padded = tf.keras.preprocessing.sequence.pad_sequences(
@@ -67,7 +66,12 @@ def preprocess_text(text: str):
67
  # ================================
68
  def predict_ticket(image, text):
69
  if image is None:
70
- return {"Critical": 0, "High": 0, "Medium": 0, "Low": 0}
 
 
 
 
 
71
 
72
  img = preprocess_image(image)
73
  txt = preprocess_text(text)
@@ -103,4 +107,4 @@ interface = gr.Interface(
103
  )
104
  )
105
 
106
- interface.launch(server_name="0.0.0.0", server_port=7860)
 
15
  from PIL import Image
16
 
17
  # ================================
18
+ # LOAD FUSION MODEL (KERAS 3 SAFE)
19
  # ================================
20
  fusion_model = tf.keras.models.load_model(
21
+ "fusion_ticket_model_final.keras",
22
+ compile=False
 
23
  )
24
 
25
+ print("✅ Fusion model loaded successfully")
26
 
27
  # ================================
28
  # LOAD TOKENIZER
 
45
  def preprocess_image(image: Image.Image):
46
  image = image.convert("RGB")
47
  image = image.resize(IMG_SIZE)
48
+ img = np.asarray(image, dtype=np.float32) / 255.0
49
  img = np.expand_dims(img, axis=0)
50
  return img
51
 
 
53
  # TEXT PREPROCESSING
54
  # ================================
55
  def preprocess_text(text: str):
56
+ if not text:
57
  text = ""
58
  seq = tokenizer.texts_to_sequences([text])
59
  padded = tf.keras.preprocessing.sequence.pad_sequences(
 
66
  # ================================
67
  def predict_ticket(image, text):
68
  if image is None:
69
+ return {
70
+ "Critical": 0.0,
71
+ "High": 0.0,
72
+ "Medium": 0.0,
73
+ "Low": 0.0
74
+ }
75
 
76
  img = preprocess_image(image)
77
  txt = preprocess_text(text)
 
107
  )
108
  )
109
 
110
+ interface.launch()