LPX
commited on
Commit
·
9b7800e
1
Parent(s):
22628b7
fix: model 8 inference
Browse files- app_optimized.py +6 -12
app_optimized.py
CHANGED
@@ -137,23 +137,17 @@ def postprocess_binary_output(output, class_names):
|
|
137 |
real_prob = 1.0 - fake_prob # Ensure Fake and Real sum to 1
|
138 |
return {class_names[0]: fake_prob, class_names[1]: real_prob}
|
139 |
|
140 |
-
# New function to infer using Gradio API for model_8
|
141 |
def infer_gradio_api(image_path):
|
142 |
client = Client("aiwithoutborders-xyz/OpenSight-Community-Forensics-Preview")
|
143 |
-
|
144 |
input_image=handle_file(image_path),
|
145 |
api_name="/simple_predict"
|
146 |
)
|
147 |
-
logger.info(f"Debug: Raw
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
logger.info(f"Debug: Parsed result_dict: {result_dict}, Extracted fake_probability: {fake_probability}")
|
153 |
-
return {"probabilities": np.array([fake_probability])} # Return as a numpy array with one element
|
154 |
-
except Exception as e:
|
155 |
-
logger.error(f"Error parsing Gradio API output: {e}. Raw output: {result_str}")
|
156 |
-
return {"probabilities": np.array([0.0])}
|
157 |
|
158 |
# New preprocess function for Gradio API
|
159 |
def preprocess_gradio_api(image: Image.Image):
|
|
|
137 |
real_prob = 1.0 - fake_prob # Ensure Fake and Real sum to 1
|
138 |
return {class_names[0]: fake_prob, class_names[1]: real_prob}
|
139 |
|
|
|
140 |
def infer_gradio_api(image_path):
|
141 |
client = Client("aiwithoutborders-xyz/OpenSight-Community-Forensics-Preview")
|
142 |
+
result_dict = client.predict(
|
143 |
input_image=handle_file(image_path),
|
144 |
api_name="/simple_predict"
|
145 |
)
|
146 |
+
logger.info(f"Debug: Raw result_dict from Gradio API (model_8): {result_dict}, type: {type(result_dict)}")
|
147 |
+
# result_dict is already a dictionary, no need for ast.literal_eval
|
148 |
+
fake_probability = result_dict.get('Fake Probability', 0.0)
|
149 |
+
logger.info(f"Debug: Parsed result_dict: {result_dict}, Extracted fake_probability: {fake_probability}")
|
150 |
+
return {"probabilities": np.array([fake_probability])} # Return as a numpy array with one element
|
|
|
|
|
|
|
|
|
|
|
151 |
|
152 |
# New preprocess function for Gradio API
|
153 |
def preprocess_gradio_api(image: Image.Image):
|