Commit
Β·
0225bda
1
Parent(s):
c96ef78
feat: Load saved models
Browse files- __pycache__/predictor.cpython-310.pyc +0 -0
- app.py +2 -38
- predictor.py +60 -0
- requirements.txt +4 -0
__pycache__/predictor.cpython-310.pyc
ADDED
|
Binary file (1.27 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
| 3 |
# π CUSTOM CSS
|
| 4 |
css_code = """
|
| 5 |
#footer-container {
|
|
@@ -20,44 +22,6 @@ css_code = """
|
|
| 20 |
"""
|
| 21 |
|
| 22 |
|
| 23 |
-
# π FUNCTIONS
|
| 24 |
-
def predict(mode, text, image_path):
|
| 25 |
-
"""
|
| 26 |
-
This placeholder function now returns a dictionary
|
| 27 |
-
in the format expected by the gr.Label component.
|
| 28 |
-
"""
|
| 29 |
-
multimodal_output = {
|
| 30 |
-
"abcat0100000": 0.05,
|
| 31 |
-
"abcat0200000": 0.10,
|
| 32 |
-
"abcat0300000": 0.20,
|
| 33 |
-
"abcat0400000": 0.45,
|
| 34 |
-
"abcat0500000": 0.20,
|
| 35 |
-
}
|
| 36 |
-
text_only_output = {
|
| 37 |
-
"abcat0100000": 0.08,
|
| 38 |
-
"abcat0200000": 0.15,
|
| 39 |
-
"abcat0300000": 0.25,
|
| 40 |
-
"abcat0400000": 0.35,
|
| 41 |
-
"abcat0500000": 0.17,
|
| 42 |
-
}
|
| 43 |
-
image_only_output = {
|
| 44 |
-
"abcat0100000": 0.10,
|
| 45 |
-
"abcat0200000": 0.20,
|
| 46 |
-
"abcat0300000": 0.30,
|
| 47 |
-
"abcat0400000": 0.25,
|
| 48 |
-
"abcat0500000": 0.15,
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
if mode == "Multimodal":
|
| 52 |
-
return multimodal_output
|
| 53 |
-
elif mode == "Text Only":
|
| 54 |
-
return text_only_output
|
| 55 |
-
elif mode == "Image Only":
|
| 56 |
-
return image_only_output
|
| 57 |
-
else:
|
| 58 |
-
return {}
|
| 59 |
-
|
| 60 |
-
|
| 61 |
def update_inputs(mode: str):
|
| 62 |
if mode == "Multimodal":
|
| 63 |
return gr.Textbox(visible=True), gr.Image(visible=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
from predictor import predict
|
| 4 |
+
|
| 5 |
# π CUSTOM CSS
|
| 6 |
css_code = """
|
| 7 |
#footer-container {
|
|
|
|
| 22 |
"""
|
| 23 |
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def update_inputs(mode: str):
|
| 26 |
if mode == "Multimodal":
|
| 27 |
return gr.Textbox(visible=True), gr.Image(visible=True)
|
predictor.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from tensorflow.keras.models import load_model
|
| 2 |
+
|
| 3 |
+
# TODO: Review Code
|
| 4 |
+
# Load the models once at the start of the script
|
| 5 |
+
print("π¬ Loading models...")
|
| 6 |
+
try:
|
| 7 |
+
text_model = load_model("./models/text_model")
|
| 8 |
+
image_model = load_model("./models/image_model")
|
| 9 |
+
multimodal_model = load_model("./models/multimodal_model")
|
| 10 |
+
print("β
Models loaded successfully!")
|
| 11 |
+
except Exception as e:
|
| 12 |
+
print(f"β Error loading models: {e}")
|
| 13 |
+
text_model = None
|
| 14 |
+
image_model = None
|
| 15 |
+
multimodal_model = None
|
| 16 |
+
|
| 17 |
+
# A placeholder for your class labels
|
| 18 |
+
CLASS_LABELS = [
|
| 19 |
+
"abcat0100000",
|
| 20 |
+
"abcat0200000",
|
| 21 |
+
"abcat0207000",
|
| 22 |
+
] # Add your actual labels
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# π FUNCTIONS
|
| 26 |
+
def predict(mode, text, image_path):
|
| 27 |
+
"""
|
| 28 |
+
This placeholder function now returns a dictionary
|
| 29 |
+
in the format expected by the gr.Label component.
|
| 30 |
+
"""
|
| 31 |
+
multimodal_output = {
|
| 32 |
+
"abcat0100000": 0.05,
|
| 33 |
+
"abcat0200000": 0.10,
|
| 34 |
+
"abcat0300000": 0.20,
|
| 35 |
+
"abcat0400000": 0.45,
|
| 36 |
+
"abcat0500000": 0.20,
|
| 37 |
+
}
|
| 38 |
+
text_only_output = {
|
| 39 |
+
"abcat0100000": 0.08,
|
| 40 |
+
"abcat0200000": 0.15,
|
| 41 |
+
"abcat0300000": 0.25,
|
| 42 |
+
"abcat0400000": 0.35,
|
| 43 |
+
"abcat0500000": 0.17,
|
| 44 |
+
}
|
| 45 |
+
image_only_output = {
|
| 46 |
+
"abcat0100000": 0.10,
|
| 47 |
+
"abcat0200000": 0.20,
|
| 48 |
+
"abcat0300000": 0.30,
|
| 49 |
+
"abcat0400000": 0.25,
|
| 50 |
+
"abcat0500000": 0.15,
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
if mode == "Multimodal":
|
| 54 |
+
return multimodal_output
|
| 55 |
+
elif mode == "Text Only":
|
| 56 |
+
return text_only_output
|
| 57 |
+
elif mode == "Image Only":
|
| 58 |
+
return image_only_output
|
| 59 |
+
else:
|
| 60 |
+
return {}
|
requirements.txt
CHANGED
|
@@ -1 +1,5 @@
|
|
| 1 |
gradio==5.44.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
gradio==5.44.0
|
| 2 |
+
tensorflow==2.15.0
|
| 3 |
+
transformers==4.44.2
|
| 4 |
+
numpy==1.26.4
|
| 5 |
+
sentence-transformers==5.1.0
|