Update app.py
Browse files
app.py
CHANGED
|
@@ -386,27 +386,30 @@ def generate_auswahl(prompt_in, file, file_history, chatbot, history, rag_option
|
|
| 386 |
|
| 387 |
##################################################
|
| 388 |
#zu einem Text-Prompt ein Bild via Stable Diffusion generieren
|
| 389 |
-
def generate_bild(prompt, chatbot, model_option_zeichnen='HuggingFace', temperature=0.5, max_new_tokens=4048,top_p=0.6, repetition_penalty=1.3):
|
| 390 |
global client
|
| 391 |
-
if (
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
|
|
|
|
|
|
|
|
|
| 410 |
|
| 411 |
|
| 412 |
##################################################
|
|
|
|
| 386 |
|
| 387 |
##################################################
|
| 388 |
#zu einem Text-Prompt ein Bild via Stable Diffusion generieren
|
| 389 |
+
def generate_bild(prompt, chatbot, model_option_zeichnen='HuggingFace', temperature=0.5, max_new_tokens=4048,top_p=0.6, repetition_penalty=1.3, validate=False):
|
| 390 |
global client
|
| 391 |
+
if (validate):
|
| 392 |
+
if (model_option_zeichnen == "Stable Diffusion"):
|
| 393 |
+
print("Bild Erzeugung HF..............................")
|
| 394 |
+
#Bild nach Anweisung zeichnen und in History darstellen...
|
| 395 |
+
data = {"inputs": prompt}
|
| 396 |
+
response = requests.post(API_URL, headers=HEADERS, json=data)
|
| 397 |
+
print("fertig Bild")
|
| 398 |
+
result = response.content
|
| 399 |
+
#Bild ausgeben
|
| 400 |
+
image = Image.open(io.BytesIO(result))
|
| 401 |
+
image_64 = umwandeln_fuer_anzeige(image)
|
| 402 |
+
chatbot[-1][1]= "<img src='data:image/png;base64,{0}'/>".format(base64.b64encode(image_64).decode('utf-8'))
|
| 403 |
+
else:
|
| 404 |
+
print("Bild Erzeugung DallE..............................")
|
| 405 |
+
#als Format ginge auch 'url', n - Anz. der erzeugten Bilder
|
| 406 |
+
response = client.images.generate(model="dall-e-3",prompt=prompt,size="1024x1024",quality="standard",n=1, response_format='b64_json')
|
| 407 |
+
#chatbot[-1][1]= "<img src='data:image/png;base64,{0}'/>".format(base64.b64encode(image_64).decode('utf-8'))
|
| 408 |
+
chatbot[-1][1] = "<img src='data:image/png;base64,{0}'/>".format(response.data[0].b64_json)
|
| 409 |
+
|
| 410 |
+
return chatbot, "Antwort KI: Success"
|
| 411 |
+
else: #noch nicht validiert ...
|
| 412 |
+
return chatbot, "Bitte erst validieren!"
|
| 413 |
|
| 414 |
|
| 415 |
##################################################
|