janasumit2911 commited on
Commit
e2bde30
·
verified ·
1 Parent(s): 3c1efad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -21,8 +21,6 @@ def detect_objects(images):
21
  def create_solutions(image_urls, names):
22
  solutions = []
23
  for image_url, prediction in zip(image_urls, names):
24
- # prediction_list = []
25
- # prediction_list.append(prediction)
26
  obj = {"url": image_url, "answer": [prediction]}
27
  solutions.append(obj)
28
  return solutions
@@ -48,13 +46,13 @@ def process_images(params):
48
  logging.error(f"Invalid JSON input: {e.msg} at line {e.lineno} column {e.colno}")
49
  return {"error": f"Invalid JSON input: {e.msg} at line {e.lineno} column {e.colno}"}
50
 
51
- image_urls = params.get("image_urls", [])
52
  # api = params.get("api", "")
53
  # job_id = params.get("job_id", "")
54
 
55
  if not image_urls:
56
- logging.error("Missing required parameters: 'image_urls'")
57
- return {"error": "Missing required parameters: 'image_urls'"}
58
 
59
  try:
60
  images = [Image.open(requests.get(url, stream=True).raw) for url in image_urls]
@@ -70,7 +68,7 @@ def process_images(params):
70
 
71
  return json.dumps({"solutions": solutions})
72
 
73
- inputt = gr.Textbox(label="Parameters (JSON format) Eg. {'image_urls':['a.jpg','b.jpg']}")
74
  outputs = gr.JSON()
75
 
76
  application = gr.Interface(fn=process_images, inputs=inputt, outputs=outputs, title="Car Colour Classification with API Integration")
 
21
  def create_solutions(image_urls, names):
22
  solutions = []
23
  for image_url, prediction in zip(image_urls, names):
 
 
24
  obj = {"url": image_url, "answer": [prediction]}
25
  solutions.append(obj)
26
  return solutions
 
46
  logging.error(f"Invalid JSON input: {e.msg} at line {e.lineno} column {e.colno}")
47
  return {"error": f"Invalid JSON input: {e.msg} at line {e.lineno} column {e.colno}"}
48
 
49
+ image_urls = params.get("urls", [])
50
  # api = params.get("api", "")
51
  # job_id = params.get("job_id", "")
52
 
53
  if not image_urls:
54
+ logging.error("Missing required parameters: 'urls'")
55
+ return {"error": "Missing required parameters: 'urls'"}
56
 
57
  try:
58
  images = [Image.open(requests.get(url, stream=True).raw) for url in image_urls]
 
68
 
69
  return json.dumps({"solutions": solutions})
70
 
71
+ inputt = gr.Textbox(label="Parameters (JSON format) Eg. {'urls':['a.jpg','b.jpg']}")
72
  outputs = gr.JSON()
73
 
74
  application = gr.Interface(fn=process_images, inputs=inputt, outputs=outputs, title="Car Colour Classification with API Integration")