Update app.py
Browse files
app.py
CHANGED
|
@@ -10,15 +10,6 @@ api_key = "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"
|
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
|
| 13 |
-
# Ensure the directory exists and set appropriate permissions
|
| 14 |
-
uploads_dir = 'uploads'
|
| 15 |
-
os.makedirs(uploads_dir, exist_ok=True)
|
| 16 |
-
|
| 17 |
-
# Function to encode the image
|
| 18 |
-
def encode_image(image_path):
|
| 19 |
-
with open(image_path, "rb") as image_file:
|
| 20 |
-
return base64.b64encode(image_file.read()).decode('utf-8')
|
| 21 |
-
|
| 22 |
@app.route('/')
|
| 23 |
def index():
|
| 24 |
return render_template('index.html')
|
|
@@ -32,19 +23,8 @@ def save_image():
|
|
| 32 |
image_data = re.sub('^data:image/.+;base64,', '', image_data)
|
| 33 |
image_data = base64.b64decode(image_data)
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
file_path = os.path.join(uploads_dir, f'captured_image_{timestamp}.png')
|
| 38 |
-
|
| 39 |
-
# Save the image to a file
|
| 40 |
-
with open(file_path, 'wb') as f:
|
| 41 |
-
f.write(image_data)
|
| 42 |
-
|
| 43 |
-
# Path to your image
|
| 44 |
-
image_path = file_path
|
| 45 |
-
|
| 46 |
-
# Getting the base64 string
|
| 47 |
-
base64_image = encode_image(image_path)
|
| 48 |
|
| 49 |
headers = {
|
| 50 |
"Content-Type": "application/json",
|
|
@@ -81,11 +61,7 @@ def save_image():
|
|
| 81 |
else:
|
| 82 |
analysis_result = "Error: ๋น๋ฅ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
| 83 |
|
| 84 |
-
return jsonify({'message': '๋ถ์์ด ์๋ฃ๋์์ต๋๋ค.', '
|
| 85 |
-
|
| 86 |
-
@app.route('/images/<filename>')
|
| 87 |
-
def get_image(filename):
|
| 88 |
-
return send_from_directory('.', filename)
|
| 89 |
|
| 90 |
if __name__ == '__main__':
|
| 91 |
app.run(host='0.0.0.0', port=7860, debug=True)
|
|
|
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
@app.route('/')
|
| 14 |
def index():
|
| 15 |
return render_template('index.html')
|
|
|
|
| 23 |
image_data = re.sub('^data:image/.+;base64,', '', image_data)
|
| 24 |
image_data = base64.b64decode(image_data)
|
| 25 |
|
| 26 |
+
# Encode image to base64 string
|
| 27 |
+
base64_image = base64.b64encode(image_data).decode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
headers = {
|
| 30 |
"Content-Type": "application/json",
|
|
|
|
| 61 |
else:
|
| 62 |
analysis_result = "Error: ๋น๋ฅ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
| 63 |
|
| 64 |
+
return jsonify({'message': '๋ถ์์ด ์๋ฃ๋์์ต๋๋ค.', 'analysis_result': analysis_result})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
if __name__ == '__main__':
|
| 67 |
app.run(host='0.0.0.0', port=7860, debug=True)
|