Spaces:
Runtime error
Runtime error
Commit
·
65b66f9
1
Parent(s):
806dc65
done
Browse files
app.py
CHANGED
@@ -9,6 +9,8 @@ from deep_translator import GoogleTranslator
|
|
9 |
# from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
|
10 |
import warnings
|
11 |
from flask import Flask
|
|
|
|
|
12 |
|
13 |
# from flask_ngrok import run_with_ngrok
|
14 |
app = Flask(__name__)
|
@@ -122,6 +124,11 @@ def upload_file():
|
|
122 |
file = request.files['file']
|
123 |
if file.filename.endswith(('.png', '.jpg', '.jpeg')):
|
124 |
image = Image.open(file.stream)
|
|
|
|
|
|
|
|
|
|
|
125 |
# Store the image in cache (replace with a more suitable storage approach)
|
126 |
image_cache['image'] = image
|
127 |
# print("Processing complete. Image stored in cache.")
|
@@ -140,7 +147,7 @@ def get_bot_response():
|
|
140 |
try:
|
141 |
if 'image' in image_cache:
|
142 |
image = image_cache['image']
|
143 |
-
print(image)
|
144 |
query = request.args.get('msg')
|
145 |
# output = query
|
146 |
output = google_response(image, query)
|
@@ -153,6 +160,7 @@ def get_bot_response():
|
|
153 |
|
154 |
@app.route("/")
|
155 |
def home():
|
|
|
156 |
return render_template("index.html")
|
157 |
|
158 |
|
|
|
9 |
# from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
|
10 |
import warnings
|
11 |
from flask import Flask
|
12 |
+
import base64
|
13 |
+
from io import BytesIO
|
14 |
|
15 |
# from flask_ngrok import run_with_ngrok
|
16 |
app = Flask(__name__)
|
|
|
124 |
file = request.files['file']
|
125 |
if file.filename.endswith(('.png', '.jpg', '.jpeg')):
|
126 |
image = Image.open(file.stream)
|
127 |
+
# Convert the image to a base64 string and store it in cache
|
128 |
+
buffered = BytesIO()
|
129 |
+
image.save(buffered, format="JPEG")
|
130 |
+
image_base64 = base64.b64encode(buffered.getvalue())
|
131 |
+
image = Image.open(BytesIO(base64.b64decode(image_base64)))
|
132 |
# Store the image in cache (replace with a more suitable storage approach)
|
133 |
image_cache['image'] = image
|
134 |
# print("Processing complete. Image stored in cache.")
|
|
|
147 |
try:
|
148 |
if 'image' in image_cache:
|
149 |
image = image_cache['image']
|
150 |
+
# print(image)
|
151 |
query = request.args.get('msg')
|
152 |
# output = query
|
153 |
output = google_response(image, query)
|
|
|
160 |
|
161 |
@app.route("/")
|
162 |
def home():
|
163 |
+
image_cache.clear()
|
164 |
return render_template("index.html")
|
165 |
|
166 |
|