zbing commited on
Commit
9e82853
1 Parent(s): dadc18c

Upload folder using huggingface_hub

Browse files
__pycache__/api.cpython-310.pyc ADDED
Binary file (2.61 kB). View file
 
api.py CHANGED
@@ -11,7 +11,7 @@ app = Flask(__name__)
11
 
12
  # Parse command line arguments
13
  parser = argparse.ArgumentParser(description='Start the Flask server with specified model and device.')
14
- parser.add_argument('--model-path', type=str, required=True, help='Path to the pretrained model')
15
  parser.add_argument('--device', type=str, choices=['cpu', 'gpu'], default='auto', help='Device to use: "cpu", "gpu", or "auto"')
16
  args = parser.parse_args()
17
 
 
11
 
12
  # Parse command line arguments
13
  parser = argparse.ArgumentParser(description='Start the Flask server with specified model and device.')
14
+ parser.add_argument('--model-path', type=str, default="models/Florence-2-base-ft", help='Path to the pretrained model')
15
  parser.add_argument('--device', type=str, choices=['cpu', 'gpu'], default='auto', help='Device to use: "cpu", "gpu", or "auto"')
16
  args = parser.parse_args()
17
 
app.py CHANGED
@@ -8,6 +8,7 @@ import threading
8
  from datetime import datetime
9
  import paho.mqtt.client as mqtt
10
  import gradio as gr
 
11
 
12
  # Constants and configuration
13
  IMAGE_PATH = "received_image.jpg"
@@ -97,12 +98,7 @@ def predict_image_json(image, task, prompt):
97
  msgid = str(datetime.now().timestamp())
98
  if task == "<OD>":
99
  prompt = ""
100
- buffered = BytesIO()
101
- image.save(buffered, format="JPEG")
102
- image_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
103
- json_data = json.dumps({"msgid": msgid, "task": task, "prompt": prompt, "image": f"data:image/jpeg;base64,{image_base64}"})
104
- response = requests.post("http://localhost:5000/predict", headers={"Content-Type": "application/json"}, data=json_data)
105
- prediction = response.json().get("prediction", {})
106
  if task == "<OPEN_VOCABULARY_DETECTION>":
107
  prediction[task] = convert_to_od_format(prediction[task])
108
  return prediction
 
8
  from datetime import datetime
9
  import paho.mqtt.client as mqtt
10
  import gradio as gr
11
+ from api import predict_image
12
 
13
  # Constants and configuration
14
  IMAGE_PATH = "received_image.jpg"
 
98
  msgid = str(datetime.now().timestamp())
99
  if task == "<OD>":
100
  prompt = ""
101
+ prediction = predict_image(image, task, prompt)
 
 
 
 
 
102
  if task == "<OPEN_VOCABULARY_DETECTION>":
103
  prediction[task] = convert_to_od_format(prediction[task])
104
  return prediction
image_history/2024-07-31_16-22-32.jpg ADDED
image_history/2024-07-31_16-23-47.jpg ADDED
received_image.jpg ADDED
received_image_annotated.jpg ADDED
requirements.txt CHANGED
@@ -1 +1 @@
1
- paho-mqtt
 
1
+ paho