Update app.py
Browse files
app.py
CHANGED
|
@@ -153,11 +153,23 @@ def add_file(history, file, prompt):
|
|
| 153 |
def file_anzeigen(file):
|
| 154 |
return gr.File(visible=True), file.name
|
| 155 |
|
| 156 |
-
def
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
def transfer_input(inputs):
|
| 163 |
textbox = reset_textbox()
|
|
@@ -378,10 +390,7 @@ def create_picture(history, prompt):
|
|
| 378 |
# using the Image module from PIL library to view the image
|
| 379 |
#Image.open(response.raw)
|
| 380 |
|
| 381 |
-
|
| 382 |
-
buffer = io.BytesIO()
|
| 383 |
-
image.save(buffer, format='PNG')
|
| 384 |
-
return buffer.getvalue()
|
| 385 |
|
| 386 |
def generate_auswahl(prompt, file, chatbot, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,):
|
| 387 |
if (prompt.find('zeichnen') != -1):
|
|
@@ -449,9 +458,9 @@ def generate_text (prompt, file, chatbot, history, rag_option, model_option, ope
|
|
| 449 |
else:
|
| 450 |
print("file bild uplad....................")
|
| 451 |
print(file)
|
| 452 |
-
image = Image.open(io.BytesIO(file_anzeigen))
|
| 453 |
-
image_64 = umwandeln_fuer_anzeige(image)
|
| 454 |
-
prompt_neu = prompt
|
| 455 |
print("prompt_neu............................")
|
| 456 |
print(prompt_neu)
|
| 457 |
history_text_und_prompt = generate_prompt_with_history_openai(prompt_neu, history)
|
|
|
|
| 153 |
def file_anzeigen(file):
|
| 154 |
return gr.File(visible=True), file.name
|
| 155 |
|
| 156 |
+
def umwandeln_fuer_anzeige(image):
|
| 157 |
+
buffer = io.BytesIO()
|
| 158 |
+
image.save(buffer, format='PNG')
|
| 159 |
+
return buffer.getvalue()
|
| 160 |
+
|
| 161 |
+
def process_image(image_path, prompt):
|
| 162 |
+
# Convert image to base64
|
| 163 |
+
with open(image_path, "rb") as image_file:
|
| 164 |
+
encoded_string = base64.b64encode(image_file.read()).decode()
|
| 165 |
+
|
| 166 |
+
# Prepare the data for the API request (specific to the API you're using)
|
| 167 |
+
data = {
|
| 168 |
+
'image': encoded_string,
|
| 169 |
+
'input': prompt,
|
| 170 |
+
}
|
| 171 |
+
return data
|
| 172 |
+
|
| 173 |
|
| 174 |
def transfer_input(inputs):
|
| 175 |
textbox = reset_textbox()
|
|
|
|
| 390 |
# using the Image module from PIL library to view the image
|
| 391 |
#Image.open(response.raw)
|
| 392 |
|
| 393 |
+
|
|
|
|
|
|
|
|
|
|
| 394 |
|
| 395 |
def generate_auswahl(prompt, file, chatbot, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,):
|
| 396 |
if (prompt.find('zeichnen') != -1):
|
|
|
|
| 458 |
else:
|
| 459 |
print("file bild uplad....................")
|
| 460 |
print(file)
|
| 461 |
+
#image = Image.open(io.BytesIO(file_anzeigen))
|
| 462 |
+
#image_64 = umwandeln_fuer_anzeige(image)
|
| 463 |
+
prompt_neu = process_image(file, prompt)
|
| 464 |
print("prompt_neu............................")
|
| 465 |
print(prompt_neu)
|
| 466 |
history_text_und_prompt = generate_prompt_with_history_openai(prompt_neu, history)
|