Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -165,13 +165,11 @@ def process_image(image_path, prompt):
|
|
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": [
|
@@ -228,7 +226,8 @@ def generate_auswahl(prompt, file, chatbot, history, rag_option, model_option, o
|
|
228 |
##################################################
|
229 |
#zu einem Text-Prompt ein Bild via Stable Diffusion generieren
|
230 |
def generate_bild(prompt, chatbot, temperature=0.5, max_new_tokens=4048,top_p=0.6, repetition_penalty=1.3):
|
231 |
-
|
|
|
232 |
#Bild nach Anweisung zeichnen und in History darstellen...
|
233 |
data = {"inputs": prompt}
|
234 |
response = requests.post(API_URL, headers=HEADERS, json=data)
|
@@ -239,7 +238,13 @@ def generate_bild(prompt, chatbot, temperature=0.5, max_new_tokens=4048,top_p=0
|
|
239 |
image_64 = umwandeln_fuer_anzeige(image)
|
240 |
chatbot[-1][1]= "<img src='data:image/png;base64,{0}'/>".format(base64.b64encode(image_64).decode('utf-8'))
|
241 |
return chatbot, "Success"
|
242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
|
244 |
|
245 |
##################################################
|
|
|
165 |
with open(image_path, "rb") as image_file:
|
166 |
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
|
167 |
|
|
|
168 |
# Prepare the data for the API request (specific to the API you're using)
|
169 |
headers = {
|
170 |
"Content-Type": "application/json",
|
171 |
"Authorization": f"Bearer {OAI_API_KEY}"
|
172 |
}
|
|
|
173 |
payload = {
|
174 |
"model": MODEL_NAME_IMAGE,
|
175 |
"messages": [
|
|
|
226 |
##################################################
|
227 |
#zu einem Text-Prompt ein Bild via Stable Diffusion generieren
|
228 |
def generate_bild(prompt, chatbot, temperature=0.5, max_new_tokens=4048,top_p=0.6, repetition_penalty=1.3):
|
229 |
+
"""
|
230 |
+
print("Bild Erzeugung HF..............................")
|
231 |
#Bild nach Anweisung zeichnen und in History darstellen...
|
232 |
data = {"inputs": prompt}
|
233 |
response = requests.post(API_URL, headers=HEADERS, json=data)
|
|
|
238 |
image_64 = umwandeln_fuer_anzeige(image)
|
239 |
chatbot[-1][1]= "<img src='data:image/png;base64,{0}'/>".format(base64.b64encode(image_64).decode('utf-8'))
|
240 |
return chatbot, "Success"
|
241 |
+
"""
|
242 |
+
print("Bild Erzeugung DallE..............................")
|
243 |
+
client = OpenAI()
|
244 |
+
#als Format ginge auch 'b64_json', n - Anz. der erzeugten Bilder
|
245 |
+
response = client.images.generate(model="dall-e-3",prompt=prompt,size="1024x1024",quality="standard",n=1, response_format=url)
|
246 |
+
chatbot[-1][1]=image_url = response.data[0].url
|
247 |
+
return chatbot, "Success"
|
248 |
|
249 |
|
250 |
##################################################
|