Spaces:
Sleeping
Sleeping
Update Vision-proxy/app.py
Browse files- Vision-proxy/app.py +25 -47
Vision-proxy/app.py
CHANGED
|
@@ -1,47 +1,25 @@
|
|
| 1 |
-
import
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
]
|
| 27 |
-
},
|
| 28 |
-
]
|
| 29 |
-
|
| 30 |
-
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
|
| 31 |
-
inputs = processor(text=prompt, images=[image], return_tensors="pt").to(DEVICE)
|
| 32 |
-
|
| 33 |
-
with torch.no_grad():
|
| 34 |
-
generated_ids = model.generate(**inputs, max_new_tokens=500)
|
| 35 |
-
|
| 36 |
-
result = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 37 |
-
return result
|
| 38 |
-
|
| 39 |
-
demo = gr.Interface(
|
| 40 |
-
fn=describe_image,
|
| 41 |
-
inputs=gr.Image(type="pil", label="Upload an Image"),
|
| 42 |
-
outputs="text",
|
| 43 |
-
title="VISIONSAGE",
|
| 44 |
-
description="Upload an image and get a detailed description."
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
demo.launch()
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify, send_from_directory
|
| 2 |
+
from flask_cors import CORS
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__, static_folder='static')
|
| 6 |
+
CORS(app) # allow all origins
|
| 7 |
+
|
| 8 |
+
HF_API_URL = "https://hf.space/embed/HawkEye01/VisionSage/api/predict/"
|
| 9 |
+
|
| 10 |
+
@app.route('/api/predict', methods=['POST'])
|
| 11 |
+
def predict():
|
| 12 |
+
try:
|
| 13 |
+
data = request.get_json()
|
| 14 |
+
response = requests.post(HF_API_URL, json=data, headers={"Content-Type": "application/json"})
|
| 15 |
+
return jsonify(response.json())
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return jsonify({"error": str(e)}), 500
|
| 18 |
+
|
| 19 |
+
# Serve HTML
|
| 20 |
+
@app.route('/')
|
| 21 |
+
def index():
|
| 22 |
+
return send_from_directory('static', 'index.html')
|
| 23 |
+
|
| 24 |
+
if __name__ == '__main__':
|
| 25 |
+
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|