Spaces:
Sleeping
Sleeping
Update app.py
Browse files4 unmodified lines56789101121 unmodified lines33343536373839404142434445464748495051525354555657585960616263646566676869360 unmodified lines4304314324334 unmodified linesimport numpy as npfrom uuid import uuid4from authlib.integrations.flask_client import OAuthfrom tensorflow.keras.models import load_modelfrom tensorflow.keras.preprocessing import image as keras_imageapp = Flask(__name__)21 unmodified lines# ===================== MODEL LOADING =====================MODEL_PATH = "model/waste_model.keras"GDRIVE_FILE_ID = "1GiRiGt6-FcIBxBzYYV17gkbvXQate4ed"def download_model_from_gdrive(file_id, dest_path):import requestsprint("Downloading model from Google Drive...")os.makedirs(os.path.dirname(dest_path), exist_ok=True)url = f"https://drive.google.com/uc?export=download&id={file_id}"session = requests.Session()response = session.get(url, stream=True)# Handle Google's virus scan warning for large filestoken = Nonefor key, value in response.cookies.items():if key.startswith("download_warning"):token = valuebreakif token:response = session.get(url, params={"confirm": token}, stream=True)with open(dest_path, "wb") as f:for chunk in response.iter_content(chunk_size=32768):if chunk:f.write(chunk)print("Model downloaded successfully.")if not os.path.exists(MODEL_PATH):download_model_from_gdrive(GDRIVE_FILE_ID, MODEL_PATH)model = load_model(MODEL_PATH)class_names = ["biodegradable", "non_recyclable", "recyclable"]# ===================== DATABASE =====================360 unmodified linesif __name__ == "__main__":init_db()port = int(os.environ.get("PORT", 8000))app.run(host="localhost", port=port, debug=False)4 unmodified lines567891021 unmodified lines32333435363738394041424344454647484950515253545556360 unmodified lines4174184194204 unmodified linesimport numpy as npfrom uuid import uuid4from authlib.integrations.flask_client import OAuthfrom tensorflow.keras.preprocessing import image as keras_imageapp = Flask(__name__)21 unmodified lines# ===================== MODEL LOADING =====================def build_model():from tensorflow.keras import layers, models, Inputweights = [np.load(f"weights/w{i}.npy", allow_pickle=True) for i in range(10)]inputs = Input(shape=(224, 224, 3))x = layers.Rescaling(1./255)(inputs)x = layers.Conv2D(16, 3, activation="relu")(x)x = layers.MaxPooling2D()(x)x = layers.Conv2D(32, 3, activation="relu")(x)x = layers.MaxPooling2D()(x)x = layers.Conv2D(64, 3, activation="relu")(x)x = layers.MaxPooling2D()(x)x = layers.Flatten()(x)x = layers.Dense(128, activation="relu")(x)outputs = layers.Dense(3, activation="softmax")(x)model = models.Model(inputs, outputs)model.set_weights(weights)return modelmodel = build_model()class_names = ["biodegradable", "non_recyclable", "recyclable"]# ===================== DATABASE =====================360 unmodified linesif __name__ == "__main__":init_db()port = int(os.environ.get("PORT", 8000))app.run(host="localhost", port=port, debug=False)
app.py+20-33