KingNish commited on
Commit
4a96ecb
·
verified ·
1 Parent(s): 0270577

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -137,6 +137,16 @@ def together_text_to_image(prompt: str):
137
  except Exception as e:
138
  return f"Error generating image from text: {e}"
139
 
 
 
 
 
 
 
 
 
 
 
140
  def together_image_to_image(image_numpy, prompt: str):
141
  """
142
  Transforms an image based on a text prompt using the Together AI API.
@@ -161,7 +171,7 @@ def together_image_to_image(image_numpy, prompt: str):
161
  model="black-forest-labs/FLUX.1-kontext-max", # Hardcoded model as requested
162
  steps=40, # Hardcoded steps as requested
163
  prompt=prompt,
164
- image_url=image_numpy
165
  )
166
  return image_completion.data[0].url
167
  except Exception as e:
 
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.
 
171
  model="black-forest-labs/FLUX.1-kontext-max", # Hardcoded model as requested
172
  steps=40, # Hardcoded steps as requested
173
  prompt=prompt,
174
+ image_base64=image_to_base64(image_numpy)
175
  )
176
  return image_completion.data[0].url
177
  except Exception as e: