alexkueck commited on
Commit
37126bf
1 Parent(s): d447d84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -1
app.py CHANGED
@@ -157,7 +157,43 @@ def umwandeln_fuer_anzeige(image):
157
  image.save(buffer, format='PNG')
158
  return buffer.getvalue()
159
 
160
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
 
163
  ###################################################
 
157
  image.save(buffer, format='PNG')
158
  return buffer.getvalue()
159
 
160
+ ##########################################
161
+ #ein hochgeladenes Bild so vorbereiten, dass OpenAI API es annehmen kann und bearbeiten
162
+ #muss ein base64 Bils sein und header und payload entsprechend konfigurieren
163
+ def process_image(image_path, prompt):
164
+ # Convert image to base64
165
+ with open(image_path, "rb") as image_file:
166
+ encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
167
+
168
+
169
+ # Prepare the data for the API request (specific to the API you're using)
170
+ headers = {
171
+ "Content-Type": "application/json",
172
+ "Authorization": f"Bearer {OAI_API_KEY}"
173
+ }
174
+
175
+ payload = {
176
+ "model": MODEL_NAME_IMAGE,
177
+ "messages": [
178
+ {
179
+ "role": "user",
180
+ "content": [
181
+ {
182
+ "type": "text",
183
+ "text": prompt
184
+ },
185
+ {
186
+ "type": "image_url",
187
+ "image_url": {
188
+ "url": f"data:image/jpeg;base64,{encoded_string}"
189
+ }
190
+ }
191
+ ]
192
+ }
193
+ ],
194
+ "max_tokens": 300
195
+ }
196
+ return headers, payload
197
 
198
 
199
  ###################################################