Update app.py
Browse files
app.py
CHANGED
@@ -136,7 +136,7 @@ os.environ["HUGGINGFACEHUB_API_TOKEN"] = HUGGINGFACEHUB_API_TOKEN
|
|
136 |
##############################################
|
137 |
#wenn löschen Button geklickt
|
138 |
def clear_all():
|
139 |
-
return gr.File(visible=False)
|
140 |
|
141 |
##############################################
|
142 |
#History - die Frage oder das File eintragen...
|
@@ -150,12 +150,12 @@ def add_text(chatbot, history, prompt, file):
|
|
150 |
chatbot = chatbot + [((file.name,), None), (prompt, None)]
|
151 |
print("chatbot nach add_text............")
|
152 |
print(chatbot)
|
153 |
-
return chatbot, history, prompt, ""
|
154 |
|
155 |
############################################
|
156 |
#nach dem Upload soll das zusätzliche Fenster mit dem image drinnen angezeigt werden
|
157 |
def file_anzeigen(file):
|
158 |
-
return gr.
|
159 |
|
160 |
##########################################
|
161 |
#Hilfsfunktion, um ein von Stable Diffusion erzeugtes Bild für die Ausgabe in der History vorzubereiten
|
@@ -411,7 +411,7 @@ def generate_auswahl(prompt, file, chatbot, history, rag_option, model_option, o
|
|
411 |
image_64 = umwandeln_fuer_anzeige(image)
|
412 |
chatbot[-1][1] = "<img src='data:image/png;base64,{0}'/>".format(base64.b64encode(image_64).decode('utf-8'))
|
413 |
history = history + [(prompt, result)]
|
414 |
-
return chatbot, history,
|
415 |
else:
|
416 |
#kein Bild hochgeladen -> auf Text antworten...
|
417 |
if (file == None):
|
@@ -426,7 +426,7 @@ def generate_auswahl(prompt, file, chatbot, history, rag_option, model_option, o
|
|
426 |
|
427 |
chatbot[-1][1] = result
|
428 |
|
429 |
-
return chatbot, history,
|
430 |
"""
|
431 |
for character in result:
|
432 |
history[-1][1] += character
|
@@ -572,9 +572,10 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
572 |
with gr.Column(min_width=70, scale=1):
|
573 |
cancelBtn = gr.Button("Stop")
|
574 |
with gr.Row():
|
575 |
-
file_display = gr.File( label=None, interactive=False, height=20, min_width=20, visible=False, scale=
|
|
|
576 |
upload = gr.UploadButton("📁", file_types=["image", "video", "audio"], scale=3)
|
577 |
-
emptyBtn = gr.ClearButton([user_input, chatbot, history, file_display
|
578 |
|
579 |
with gr.Column():
|
580 |
with gr.Column(min_width=50, scale=1):
|
@@ -638,7 +639,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
638 |
max_context_length_tokens,
|
639 |
repetition_penalty
|
640 |
],
|
641 |
-
outputs=[chatbot, history,
|
642 |
show_progress=True,
|
643 |
)
|
644 |
|
@@ -649,13 +650,13 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
649 |
|
650 |
# Chatbot
|
651 |
transfer_input_args = dict(
|
652 |
-
fn=add_text, inputs=[chatbot, history, user_input, upload], outputs=[chatbot, history, user_question, user_input
|
653 |
)
|
654 |
|
655 |
predict_event1 = user_input.submit(**transfer_input_args, queue=False,).then(**predict_args)
|
656 |
predict_event2 = submitBtn.click(**transfer_input_args, queue=False,).then(**predict_args)
|
657 |
-
predict_event3 = upload.upload(file_anzeigen, [upload], [
|
658 |
-
emptyBtn.click(clear_all, [], [file_display])
|
659 |
|
660 |
cancelBtn.click(
|
661 |
cancels=[predict_event1,predict_event2, predict_event3 ]
|
|
|
136 |
##############################################
|
137 |
#wenn löschen Button geklickt
|
138 |
def clear_all():
|
139 |
+
return gr.File(visible=False), gr.Image(visible=False)
|
140 |
|
141 |
##############################################
|
142 |
#History - die Frage oder das File eintragen...
|
|
|
150 |
chatbot = chatbot + [((file.name,), None), (prompt, None)]
|
151 |
print("chatbot nach add_text............")
|
152 |
print(chatbot)
|
153 |
+
return chatbot, history, prompt, "" #gr.Image( label=None, size=(30,30), visible=False, scale=1) #gr.Textbox(value="", interactive=False)
|
154 |
|
155 |
############################################
|
156 |
#nach dem Upload soll das zusätzliche Fenster mit dem image drinnen angezeigt werden
|
157 |
def file_anzeigen(file):
|
158 |
+
return gr.Image(visible=True), file
|
159 |
|
160 |
##########################################
|
161 |
#Hilfsfunktion, um ein von Stable Diffusion erzeugtes Bild für die Ausgabe in der History vorzubereiten
|
|
|
411 |
image_64 = umwandeln_fuer_anzeige(image)
|
412 |
chatbot[-1][1] = "<img src='data:image/png;base64,{0}'/>".format(base64.b64encode(image_64).decode('utf-8'))
|
413 |
history = history + [(prompt, result)]
|
414 |
+
return chatbot, history, "Success"
|
415 |
else:
|
416 |
#kein Bild hochgeladen -> auf Text antworten...
|
417 |
if (file == None):
|
|
|
426 |
|
427 |
chatbot[-1][1] = result
|
428 |
|
429 |
+
return chatbot, history, "Success"
|
430 |
"""
|
431 |
for character in result:
|
432 |
history[-1][1] += character
|
|
|
572 |
with gr.Column(min_width=70, scale=1):
|
573 |
cancelBtn = gr.Button("Stop")
|
574 |
with gr.Row():
|
575 |
+
file_display = gr.File( label=None, interactive=False, height=20, min_width=20, visible=False, scale=0)
|
576 |
+
image_display = gr.Image(label = None, shape=[30,30], visible=False, scale = 1)
|
577 |
upload = gr.UploadButton("📁", file_types=["image", "video", "audio"], scale=3)
|
578 |
+
emptyBtn = gr.ClearButton([user_input, chatbot, history, file_display, image_display], value="🧹 Neue Session", scale=3)
|
579 |
|
580 |
with gr.Column():
|
581 |
with gr.Column(min_width=50, scale=1):
|
|
|
639 |
max_context_length_tokens,
|
640 |
repetition_penalty
|
641 |
],
|
642 |
+
outputs=[chatbot, history, status_display], #[chatbot, history, status_display]
|
643 |
show_progress=True,
|
644 |
)
|
645 |
|
|
|
650 |
|
651 |
# Chatbot
|
652 |
transfer_input_args = dict(
|
653 |
+
fn=add_text, inputs=[chatbot, history, user_input, upload], outputs=[chatbot, history, user_question, user_input], show_progress=True
|
654 |
)
|
655 |
|
656 |
predict_event1 = user_input.submit(**transfer_input_args, queue=False,).then(**predict_args)
|
657 |
predict_event2 = submitBtn.click(**transfer_input_args, queue=False,).then(**predict_args)
|
658 |
+
predict_event3 = upload.upload(file_anzeigen, [upload], [image_display, file_display] ) #.then(**predict_args)
|
659 |
+
emptyBtn.click(clear_all, [], [file_display, image_display])
|
660 |
|
661 |
cancelBtn.click(
|
662 |
cancels=[predict_event1,predict_event2, predict_event3 ]
|