GRATITUD3 commited on
Commit
51536c9
·
1 Parent(s): 8fb99f3
Files changed (1) hide show
  1. app.py +27 -25
app.py CHANGED
@@ -8,52 +8,54 @@ import cv2
8
 
9
  from autodistill.core.custom_detection_model import CustomDetectionModel
10
 
 
 
 
 
 
11
  MARKDOWN = """
12
  # NESGPT-AutoAnnotator
13
  Grounding DINO for Zero-Shot Carbon Sink Identification and Object Segmentation
14
  ."""
15
 
16
- def respond(api_key, input_image, dino_prompt, gpt_prompt):
17
  input_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB)
18
- cv2.imwrite("input.jpg", input_image)
19
-
20
- DINOGPT = CustomDetectionModel(
21
- detection_model=GroundingDINO(
22
- CaptionOntology({dino_prompt: dino_prompt})
23
- ),
24
- classification_model=GPT4V(
25
- CaptionOntology({k: k for k in gpt_prompt.split(", ")}),
26
- api_key=api_key
 
 
27
  )
28
- )
29
 
30
- results = DINOGPT.predict("input.jpg")
31
 
32
- result = plot(
33
- image=cv2.imread("input.jpg"),
34
- detections=results,
35
- classes=gpt_prompt.split(", "),
36
- raw=True
37
- )
38
 
39
- return result
40
 
41
  with gr.Blocks() as demo:
42
  gr.Markdown(MARKDOWN)
43
  with gr.Row():
44
  with gr.Column():
45
- api_key_textbox = gr.Textbox(
46
- label="OpenAI API KEY", type="password")
47
- dino_prompt = buildings . parks .
48
- gpt_prompt = carbon sinks
49
  input_image = gr.Image(type="numpy", label="Input Location")
50
  with gr.Column():
51
  output_image = gr.Image(type="numpy", label="Carbon Sink Identifier")
52
- submit_button = gr.Button()
53
 
54
  submit_button.click(
55
  fn=respond,
56
- inputs=[api_key_textbox, input_image, dino_prompt, gpt_prompt],
57
  outputs=[output_image]
58
  )
59
 
 
8
 
9
  from autodistill.core.custom_detection_model import CustomDetectionModel
10
 
11
+ # Hardcoded values - ensure to protect the API key
12
+ api_key = "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"
13
+ dino_prompt = "buildings . parks ."
14
+ gpt_prompt = "carbon sinks"
15
+
16
  MARKDOWN = """
17
  # NESGPT-AutoAnnotator
18
  Grounding DINO for Zero-Shot Carbon Sink Identification and Object Segmentation
19
  ."""
20
 
21
+ def respond(input_image):
22
  input_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB)
23
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
24
+ cv2.imwrite(temp_file.name, input_image)
25
+
26
+ DINOGPT = CustomDetectionModel(
27
+ detection_model=GroundingDINO(
28
+ CaptionOntology({dino_prompt: dino_prompt})
29
+ ),
30
+ classification_model=GPT4V(
31
+ CaptionOntology({k: k for k in gpt_prompt.split(", ")}),
32
+ api_key=api_key # Use the hardcoded API key
33
+ )
34
  )
 
35
 
36
+ results = DINOGPT.predict(temp_file.name)
37
 
38
+ result_image = plot(
39
+ image=cv2.imread(temp_file.name),
40
+ detections=results,
41
+ classes=gpt_prompt.split(", "),
42
+ raw=True
43
+ )
44
 
45
+ return result_image
46
 
47
  with gr.Blocks() as demo:
48
  gr.Markdown(MARKDOWN)
49
  with gr.Row():
50
  with gr.Column():
 
 
 
 
51
  input_image = gr.Image(type="numpy", label="Input Location")
52
  with gr.Column():
53
  output_image = gr.Image(type="numpy", label="Carbon Sink Identifier")
54
+ submit_button = gr.Button("Identify Carbon Sinks")
55
 
56
  submit_button.click(
57
  fn=respond,
58
+ inputs=[input_image],
59
  outputs=[output_image]
60
  )
61