Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,49 +8,6 @@ headers = {
|
|
8 |
"x-api-key": os.getenv("JIGSAWSTACK_API_KEY")
|
9 |
}
|
10 |
|
11 |
-
|
12 |
-
def detect_objects(image_url=None, file_store_key=None):
|
13 |
-
if not image_url and not file_store_key:
|
14 |
-
return "β Please provide either an image URL or file store key.", [], "", ""
|
15 |
-
|
16 |
-
if image_url and file_store_key:
|
17 |
-
return "β Provide only one: image URL or file store key.", [], "", ""
|
18 |
-
|
19 |
-
try:
|
20 |
-
payload = {}
|
21 |
-
if image_url:
|
22 |
-
payload["url"] = image_url
|
23 |
-
if file_store_key:
|
24 |
-
payload["file_store_key"] = file_store_key
|
25 |
-
|
26 |
-
response = requests.post(f"{BASE_URL}/ai/object_detection", headers=headers, json=payload)
|
27 |
-
if response.status_code != 200:
|
28 |
-
return f"β Error: {response.status_code} - {response.text}", [], "", ""
|
29 |
-
|
30 |
-
result = response.json()
|
31 |
-
if not result.get("success"):
|
32 |
-
return "β Detection failed.", [], "", ""
|
33 |
-
|
34 |
-
status = "β
Detection successful!"
|
35 |
-
tags = result.get("tags", [])
|
36 |
-
objects = result.get("objects", [])
|
37 |
-
description = f"Image Size: {result.get('width')} x {result.get('height')}\n\n"
|
38 |
-
|
39 |
-
for obj in objects:
|
40 |
-
bounds = obj.get("bounds", {})
|
41 |
-
bound_text = ""
|
42 |
-
if bounds.get("top_left") and bounds.get("top_right"):
|
43 |
-
tl = bounds["top_left"]
|
44 |
-
tr = bounds["top_right"]
|
45 |
-
bound_text = f"Bounds: ({tl['x']}, {tl['y']}) to ({tr['x']}, {tr['y']})"
|
46 |
-
description += f"β’ {obj['name']} (Confidence: {obj['confidence']:.2f})\n {bound_text}\n"
|
47 |
-
|
48 |
-
raw_json = json.dumps(result, indent=2)
|
49 |
-
return status, tags, description.strip(), raw_json
|
50 |
-
|
51 |
-
except Exception as e:
|
52 |
-
return f"β Error: {str(e)}", [], "", ""
|
53 |
-
|
54 |
def web_ai_search(query, ai_overview, safe_search, spell_check, deep_research, max_depth, max_breadth, max_output_tokens, target_output_tokens):
|
55 |
if not query or not query.strip():
|
56 |
return "β Please enter a search query.", "", [], ""
|
|
|
8 |
"x-api-key": os.getenv("JIGSAWSTACK_API_KEY")
|
9 |
}
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def web_ai_search(query, ai_overview, safe_search, spell_check, deep_research, max_depth, max_breadth, max_output_tokens, target_output_tokens):
|
12 |
if not query or not query.strip():
|
13 |
return "β Please enter a search query.", "", [], ""
|