I’m encountering a persistent issue when trying to deploy my Gradio application on Hugging Face Spaces, and I would greatly appreciate any insights or assistance.
Problem Description: My Gradio Space continuously fails with the error message: "Exit code: 0. Reason: application does not seem to be initialized". This happens despite the application successfully loading my TensorFlow model. Looking at the logs, there is no indication that the Gradio web server (like Gunicorn/Uvicorn) is starting or listening on the required port.
Project Details:
Goal: Image classification (hair type).
Frameworks: TensorFlow, Keras, Gradio.
Model File:hair_type_classifier_model.h5
My Setup and What I’ve Checked:
app.py: I’ve meticulously checked my app.py file. It’s correctly configured with app = gr.Interface(...) and app.launch(share=False) (since it’s for Spaces deployment). I’ve ensured load_model(..., compile=False) is used.
requirements.txt: All dependencies are specified with exact versions (e.g., tensorflow==2.18.0, gradio==5.31.0).
Model Loading: As visible in the logs below, the line "Model berhasil dimuat." (Model loaded successfully) indicates that the model file is found and loaded without issues.
Hugging Face Space: I have tried deleting the existing Space and creating a completely new one from scratch, then re-uploading all files (app.py, requirements.txt, hair_type_classifier_model.h5), but the error persists.
Logs: Here are the relevant parts of my logs from the latest failed attempt:
I am writing to you as a fellow member of the Hugging Face forum, following the discussion regarding the “‘Application does not seem to be initialized’” error with Gradio apps on Hugging Face Spaces.
I noticed that your Space, “Hairnet Test” (huggingface.co), appears to be running successfully. My own application is still encountering a persistent initialization issue despite trying various solutions.
I would be very grateful if you would be willing to share some insights or tips on how you managed to get your Gradio application working on Hugging Face Spaces. Were there any specific configurations, app.py file structures, or particular deployment steps you followed that could help me?
My application is also related to hair type classification, and I keep getting the same error even though the model loads successfully. I have attached my
app.py and requirements.txt files for your reference.
Thank you very much for your time and any assistance you might be able to offer.
I wrote requirements.txt and README.md. I only changed two lines in app.py.
LOADED_MODEL = "debug" # just to break "if LOADED_MODEL is not None:"
# --- 5. Antarmuka Gradio ---
if LOADED_MODEL is not None:
# Ganti 'interface' menjadi 'app'
app = gr.Interface(
fn=predict_hair_type,
inputs=gr.Image(type="numpy", label="Unggah Gambar Model Rambut"),
outputs=gr.Markdown(label="Hasil Prediksi dan Rekomendasi"),
title="Klasifikasi Tipe Rambut dan Rekomendasi Perawatan",
description="Unggah gambar model rambut untuk mendapatkan prediksi tipe rambut (Curly, Dreadlocks, Kinky, Straight, Wavy) dan rekomendasi perawatan.",
examples=[ # Opsional: Tambahkan contoh gambar untuk dicoba
# Contoh gambar ini perlu ada di folder 'examples' di Spaces Anda
# atau ganti dengan URL gambar publik jika ingin langsung dari internet
# "./examples/curly_example.jpg",
# "./examples/straight_example.jpg"
]
)
# Tambahkan baris ini untuk mengaktifkan antrean Gradio
#app.queue() # .launch() is missing!
app.queue().launch() # <= Added