shorndrup commited on
Commit
2d88cb5
·
1 Parent(s): 58ea192
Files changed (2) hide show
  1. app.py +10 -9
  2. test.py +2 -7
app.py CHANGED
@@ -20,13 +20,14 @@ def predict(image):
20
  response = {"message": "Detection successful!"}
21
  return response
22
 
23
- # Create a Blocks interface
24
- with gr.Blocks() as interface:
25
- with gr.Row():
26
- image_input = gr.Image(type="pil")
27
- output = gr.JSON()
28
- image_input.upload(predict, inputs=image_input, outputs=output)
29
-
30
- # Launch the interface with queue enabled
31
- interface.launch()
32
 
 
 
 
20
  response = {"message": "Detection successful!"}
21
  return response
22
 
23
+ # Create a Gradio interface and enable the API mode
24
+ interface = gr.Interface(
25
+ fn=predict,
26
+ inputs="image",
27
+ outputs="json",
28
+ allow_flagging="never",
29
+ live=True # Allows the API endpoint to remain active
30
+ )
 
31
 
32
+ # Launch the interface with API mode enabled
33
+ interface.launch(server_name="0.0.0.0", server_port=7860, share=True)
test.py CHANGED
@@ -3,7 +3,7 @@ import json
3
 
4
  # Replace with your actual Space URL
5
  API_URL = "https://shorndrup-owlvit-api.hf.space/predict"
6
- image_path = r"C:/Users/Administrator/Downloads/pokedex/images/solrock.png"
7
 
8
  with open(image_path, "rb") as image_file:
9
  files = {"data": image_file}
@@ -13,9 +13,4 @@ with open(image_path, "rb") as image_file:
13
  print(response.text)
14
 
15
  # Try parsing JSON if the response is valid JSON
16
- try:
17
- print(response.json())
18
- except requests.exceptions.JSONDecodeError:
19
- print("Response is not in JSON format")
20
- print(f"Status Code: {response.status_code}")
21
- print(response.headers)
 
3
 
4
  # Replace with your actual Space URL
5
  API_URL = "https://shorndrup-owlvit-api.hf.space/predict"
6
+ image_path = "C:/Users/Administrator/Downloads/pokedex/images/solrock.png"
7
 
8
  with open(image_path, "rb") as image_file:
9
  files = {"data": image_file}
 
13
  print(response.text)
14
 
15
  # Try parsing JSON if the response is valid JSON
16
+ print(response.json())