KingNish commited on
Commit
9f0af1b
·
verified ·
1 Parent(s): ac09f84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -137,16 +137,27 @@ def together_text_to_image(prompt: str):
137
  except Exception as e:
138
  return f"Error generating image from text: {e}"
139
 
140
- def image_to_base64(image_path):
141
  try:
142
- with open(image_path, "rb") as image_file:
143
- base64_string = base64.b64encode(image_file.read()).decode('utf-8')
144
- return base64_string
 
 
 
 
145
  except FileNotFoundError:
146
  return "Error: File not found. Please check the image path."
147
  except Exception as e:
148
  return f"An error occurred: {e}"
149
 
 
 
 
 
 
 
 
150
  def together_image_to_image(image_numpy, prompt: str):
151
  """
152
  Transforms an image based on a text prompt using the Together AI API.
@@ -173,7 +184,7 @@ def together_image_to_image(image_numpy, prompt: str):
173
  model="black-forest-labs/FLUX.1-kontext-max", # Hardcoded model as requested
174
  steps=40, # Hardcoded steps as requested
175
  prompt=prompt,
176
- image_base64=image_to_base64(image_numpy)
177
  )
178
  return image_completion.data[0].url
179
  except Exception as e:
 
137
  except Exception as e:
138
  return f"Error generating image from text: {e}"
139
 
140
+ def image_to_url(image_path):
141
  try:
142
+ url = 'https://uguu.se/upload'
143
+
144
+ with open(image_path, 'rb') as f:
145
+ files = {'files[]': (image_path, f)}
146
+ response = requests.post(url, files=files)
147
+ response_json = response.json()
148
+ return response_json['files'][0]['url']
149
  except FileNotFoundError:
150
  return "Error: File not found. Please check the image path."
151
  except Exception as e:
152
  return f"An error occurred: {e}"
153
 
154
+ import requests
155
+
156
+ # Replace with your file path
157
+
158
+ response_json = response.json()
159
+ print(response_json['files'][0]['url'])
160
+
161
  def together_image_to_image(image_numpy, prompt: str):
162
  """
163
  Transforms an image based on a text prompt using the Together AI API.
 
184
  model="black-forest-labs/FLUX.1-kontext-max", # Hardcoded model as requested
185
  steps=40, # Hardcoded steps as requested
186
  prompt=prompt,
187
+ image_url=image_to_url(image_numpy)
188
  )
189
  return image_completion.data[0].url
190
  except Exception as e: