Update app.py
Browse files
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
|
141 |
try:
|
142 |
-
|
143 |
-
|
144 |
-
|
|
|
|
|
|
|
|
|
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 |
-
|
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:
|