NimcoX commited on
Commit
383044e
·
verified ·
1 Parent(s): c8c71ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -16
app.py CHANGED
@@ -1,18 +1,19 @@
1
- # Install dependencies (Hugging Face handles these in requirements.txt usually)
2
- from huggingface_hub import login, hf_hub_download
3
- import tensorflow as tf
4
  import os
 
 
 
 
 
5
  import gradio as gr
6
  import numpy as np
7
  from PIL import Image
8
 
9
- # Hugging Face login (token not required in public Spaces, skip if not private)
10
- # login(token="your_token_here") # Optional
11
-
12
- # Download model
13
  model_path = hf_hub_download(repo_id="Owos/tb-classifier", filename="tb_model.h5")
14
  model = tf.keras.models.load_model(model_path)
15
 
 
16
  def predict_tb(img: Image.Image):
17
  try:
18
  image = img.convert("RGB").resize((224, 224))
@@ -25,12 +26,3 @@ def predict_tb(img: Image.Image):
25
  except Exception as e:
26
  return f"❌ Error during prediction: {str(e)}"
27
 
28
- iface = gr.Interface(
29
- fn=predict_tb,
30
- inputs=gr.Image(type="pil", label="Upload Chest X-ray Image"),
31
- outputs="text",
32
- title="🩻 Tuberculosis Detection from Chest X-ray",
33
- description="Upload a chest X-ray to detect signs of Tuberculosis using an AI model (ResNet50). For educational & demo use only."
34
- )
35
-
36
- iface.launch()
 
1
+ # Disable GPU to avoid CUDA errors on Hugging Face Spaces
 
 
2
  import os
3
+ os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
4
+
5
+ # Install dependencies
6
+ from huggingface_hub import hf_hub_download
7
+ import tensorflow as tf
8
  import gradio as gr
9
  import numpy as np
10
  from PIL import Image
11
 
12
+ # Download model from Hugging Face Hub
 
 
 
13
  model_path = hf_hub_download(repo_id="Owos/tb-classifier", filename="tb_model.h5")
14
  model = tf.keras.models.load_model(model_path)
15
 
16
+ # Define prediction function
17
  def predict_tb(img: Image.Image):
18
  try:
19
  image = img.convert("RGB").resize((224, 224))
 
26
  except Exception as e:
27
  return f"❌ Error during prediction: {str(e)}"
28