Spaces:
Running
Running
Upload 2 files
Browse files- main.py +18 -30
- requirements.txt +7 -5
main.py
CHANGED
@@ -98,35 +98,23 @@ class ImagePredictor:
|
|
98 |
raise RuntimeError("Model loading failed.") from e
|
99 |
|
100 |
# --- Prediction Method ---
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
""
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
with torch.no_grad():
|
119 |
-
outputs = self.model(pixel_values=pixel_values)
|
120 |
-
logits = outputs.logits
|
121 |
-
|
122 |
-
# Get probabilities and format output
|
123 |
-
probabilities = F.softmax(logits, dim=-1)[0] # Get probabilities for the first image
|
124 |
-
confidences = {self.id2label[i]: float(prob) for i, prob in enumerate(probabilities)}
|
125 |
-
return confidences
|
126 |
-
|
127 |
-
except Exception as e:
|
128 |
-
print(f"Error during prediction: {e}")
|
129 |
-
return {"Error": f"Prediction failed: {str(e)}"}
|
130 |
|
131 |
|
132 |
# --- Main Execution Logic ---
|
@@ -159,7 +147,7 @@ if predictor and predictor.model: # Check if predictor initialized successfully
|
|
159 |
|
160 |
print("Launching Gradio interface...")
|
161 |
# Set share=True as requested
|
162 |
-
iface.launch(share=True, debug=True, show_error=True)
|
163 |
|
164 |
except Exception as e:
|
165 |
print(f"Error creating or launching Gradio interface: {e}")
|
|
|
98 |
raise RuntimeError("Model loading failed.") from e
|
99 |
|
100 |
# --- Prediction Method ---
|
101 |
+
# Inside the ImagePredictor class:
|
102 |
+
def predict(self, image: Image.Image):
|
103 |
+
print("--- Predict function called ---") # Check if this even prints in Space logs
|
104 |
+
if image is None:
|
105 |
+
print("Input image is None")
|
106 |
+
return None
|
107 |
+
try:
|
108 |
+
# Simulate some processing time
|
109 |
+
import time
|
110 |
+
time.sleep(0.1)
|
111 |
+
# Return a dummy dictionary, bypassing all model/transform logic
|
112 |
+
dummy_output = {"fake": 0.6, "real": 0.4} # Use your actual labels
|
113 |
+
print(f"Returning dummy output: {dummy_output}")
|
114 |
+
return dummy_output
|
115 |
+
except Exception as e:
|
116 |
+
print(f"Error in *simplified* predict: {e}")
|
117 |
+
return {"Error": f"Simplified prediction failed: {str(e)}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
|
120 |
# --- Main Execution Logic ---
|
|
|
147 |
|
148 |
print("Launching Gradio interface...")
|
149 |
# Set share=True as requested
|
150 |
+
iface.launch(share=True, debug=True, show_error=True).queue()
|
151 |
|
152 |
except Exception as e:
|
153 |
print(f"Error creating or launching Gradio interface: {e}")
|
requirements.txt
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
1 |
+
transformers>=4.30.0 # Or a specific recent version
|
2 |
+
torch>=2.0.0 # Or a specific recent version compatible with transformers & cuda version in space
|
3 |
+
torchvision>=0.15.0 # Or a specific recent version compatible with torch
|
4 |
+
gradio>=4.0.0 # Or a specific recent version
|
5 |
+
Pillow>=9.0.0
|
6 |
+
accelerate>=0.20.0 # Often helpful, especially with safetensors
|
7 |
+
numpy
|