Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -158,6 +158,39 @@ def api_restart_space():
|
|
| 158 |
'message': f"Error: {str(e)}"
|
| 159 |
}), 500
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
@app.route('/search_images', methods=['GET'])
|
| 162 |
def api_search_images():
|
| 163 |
try:
|
|
|
|
| 158 |
'message': f"Error: {str(e)}"
|
| 159 |
}), 500
|
| 160 |
|
| 161 |
+
@app.route('/get_space_status', methods=['GET'])
|
| 162 |
+
def get_space_status():
|
| 163 |
+
"""API route to get the status of a Hugging Face Space."""
|
| 164 |
+
space_id = request.args.get('space_id') # Expecting the space_id as a query parameter
|
| 165 |
+
|
| 166 |
+
if not space_id:
|
| 167 |
+
return jsonify({'error': 'space_id parameter is required'}), 400
|
| 168 |
+
|
| 169 |
+
try:
|
| 170 |
+
hfapi = HfApi()
|
| 171 |
+
|
| 172 |
+
# Get information about the space
|
| 173 |
+
space_info = hfapi.get_space_info(space_id, token=HF_TOKEN)
|
| 174 |
+
|
| 175 |
+
# Extract relevant details from the space_info (you can modify this based on your needs)
|
| 176 |
+
status = space_info.get('status', 'Unknown') # Assuming 'status' field is present
|
| 177 |
+
description = space_info.get('description', 'No description available')
|
| 178 |
+
|
| 179 |
+
return jsonify({
|
| 180 |
+
'success': True,
|
| 181 |
+
'space_id': space_id,
|
| 182 |
+
'status': status,
|
| 183 |
+
'description': description,
|
| 184 |
+
'space_info': space_info
|
| 185 |
+
}), 200
|
| 186 |
+
|
| 187 |
+
except Exception as e:
|
| 188 |
+
return jsonify({
|
| 189 |
+
'success': False,
|
| 190 |
+
'message': f"Error: {str(e)}"
|
| 191 |
+
}), 500
|
| 192 |
+
|
| 193 |
+
|
| 194 |
@app.route('/search_images', methods=['GET'])
|
| 195 |
def api_search_images():
|
| 196 |
try:
|