alexkueck commited on
Commit
c0c221f
1 Parent(s): ecbd002

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -3
app.py CHANGED
@@ -276,7 +276,7 @@ def create_assistant_suche(prompt):
276
  #########################################################
277
  #Funktion wird direkt aufgerufen aus der GUI - von hier muss auch die Rückmeldung kommen....
278
  #man kann einen Text-Prompt eingeben (mit oder ohne RAG), dazu ein Image hochladen, ein Bild zu einem reinen textprompt erzeugen lassen
279
- def generate_auswahl(prompt_in, file, file_history, 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,top_k=35):
280
  global splittet, db
281
  #wenn RAG angeschaltet - Vektorstore initialisieren
282
  #aber nur, wenn es noch nicht geshehen ist (splittet = False)
@@ -336,7 +336,7 @@ def generate_auswahl(prompt_in, file, file_history, chatbot, history, rag_option
336
 
337
  ##################################################
338
  #zu einem Text-Prompt ein Bild via Stable Diffusion generieren
339
- def generate_bild(prompt, chatbot, model_option_zeichnen='HuggingFace', temperature=0.5, max_new_tokens=4048,top_p=0.6, repetition_penalty=1.3):
340
  global client
341
  if (model_option_zeichnen == "Stable Diffusion"):
342
  print("Bild Erzeugung HF..............................")
@@ -476,6 +476,18 @@ def generate_text (prompt, chatbot, history, rag_option, model_option, openai_ap
476
 
477
  return result, suche_im_Netz
478
 
 
 
 
 
 
 
 
 
 
 
 
 
479
 
480
 
481
  ################################################
@@ -507,6 +519,7 @@ with gr.Blocks(css=customCSS, theme=themeAlex) as demo:
507
  #Session Variablen, um Weete zu speichern, auch wenn die Felder in der GUI bereits wieder leer sind
508
  # history parallel zu chatbot speichern - da in chatbot bei Bildern zum Anzeigen in der GUI die Bilder speziell formatiert werden,
509
  # für die Übergabe an die ki aber der Pfad zum Bild behalten werden muss - was in der history der Fall ist!
 
510
  history = gr.State([])
511
  uploaded_file_paths= gr.State([])
512
  #alle chats einer Session sammeln
@@ -523,6 +536,9 @@ with gr.Blocks(css=customCSS, theme=themeAlex) as demo:
523
  # Tab zum Chatbot mit Text oder Bildeingabe
524
  ################################################
525
  gr.Markdown(description_top)
 
 
 
526
  with gr.Tab("LI Chatbot"):
527
  with gr.Row():
528
  #gr.HTML("LI Chatot")
@@ -668,7 +684,8 @@ with gr.Blocks(css=customCSS, theme=themeAlex) as demo:
668
  max_length_tokens,
669
  max_context_length_tokens,
670
  repetition_penalty,
671
- top_k
 
672
  ],
673
  outputs=[chatbot, history, attached_file, attached_file_history, status_display],
674
  show_progress=True,
@@ -683,6 +700,10 @@ with gr.Blocks(css=customCSS, theme=themeAlex) as demo:
683
  fn=add_text, inputs=[chatbot, history, user_input, attached_file, attached_file_history], outputs=[chatbot, history, user_question, attached_file, attached_file_history, image_display , user_input], show_progress=True
684
  )
685
 
 
 
 
 
686
  predict_event1 = user_input.submit(**transfer_input_args, queue=False,).then(**predict_args)
687
  predict_event2 = submitBtn.click(**transfer_input_args, queue=False,).then(**predict_args)
688
  predict_event3 = upload.upload(file_anzeigen, [upload], [image_display, image_display, attached_file] ) #.then(**predict_args)
@@ -704,6 +725,7 @@ with gr.Blocks(css=customCSS, theme=themeAlex) as demo:
704
  chatbot_bild,
705
  model_option_zeichnen,
706
  #additional_inputs,
 
707
  ],
708
  outputs=[chatbot_bild, status_display2], #[chatbot, history, status_display]
709
  show_progress=True,
 
276
  #########################################################
277
  #Funktion wird direkt aufgerufen aus der GUI - von hier muss auch die Rückmeldung kommen....
278
  #man kann einen Text-Prompt eingeben (mit oder ohne RAG), dazu ein Image hochladen, ein Bild zu einem reinen textprompt erzeugen lassen
279
+ def generate_auswahl(prompt_in, file, file_history, 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,top_k=35, validate=False):
280
  global splittet, db
281
  #wenn RAG angeschaltet - Vektorstore initialisieren
282
  #aber nur, wenn es noch nicht geshehen ist (splittet = False)
 
336
 
337
  ##################################################
338
  #zu einem Text-Prompt ein Bild via Stable Diffusion generieren
339
+ 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):
340
  global client
341
  if (model_option_zeichnen == "Stable Diffusion"):
342
  print("Bild Erzeugung HF..............................")
 
476
 
477
  return result, suche_im_Netz
478
 
479
+
480
+ ########################################
481
+ # Bot- test gegen schädliche Bots die die Anwendung testen...
482
+ # Funktion zur Überprüfung der Benutzereingabe
483
+ # Funktion zur Überprüfung der Eingabe und Aktivierung der Hauptanwendung
484
+ def validate_input(user_input_validate, validate=False):
485
+ user_input_hashed = hash_input(user_input_validate)
486
+ if user_input_hashed == hash_input(ANTI_BOT_PW):
487
+ return "Richtig! Weiter gehts... ", True, gr.Textbox(visible=False), gr.Button(visible=False)
488
+ else:
489
+ return "Falsche Antwort!!!!!!!!!", False, gr.Textbox(label = "", placeholder="Bitte tippen Sie das oben im Moodle Kurs angegebene Wort ein, um zu beweisen, dass Sie kein Bot sind.", visible=True, scale= 5), gr.Button("Validieren", visible = True)
490
+
491
 
492
 
493
  ################################################
 
519
  #Session Variablen, um Weete zu speichern, auch wenn die Felder in der GUI bereits wieder leer sind
520
  # history parallel zu chatbot speichern - da in chatbot bei Bildern zum Anzeigen in der GUI die Bilder speziell formatiert werden,
521
  # für die Übergabe an die ki aber der Pfad zum Bild behalten werden muss - was in der history der Fall ist!
522
+ validate = gr.State(False)
523
  history = gr.State([])
524
  uploaded_file_paths= gr.State([])
525
  #alle chats einer Session sammeln
 
536
  # Tab zum Chatbot mit Text oder Bildeingabe
537
  ################################################
538
  gr.Markdown(description_top)
539
+ with gr.Row():
540
+ user_input_validate =gr.Textbox(label= "Bitte das oben im Moodle Kurs angegebene Wort eingeben, um die Anwendung zu starten", visible=True, interactive=True, scale= 7)
541
+ validate_btn = gr.Button("Validieren", visible = True)
542
  with gr.Tab("LI Chatbot"):
543
  with gr.Row():
544
  #gr.HTML("LI Chatot")
 
684
  max_length_tokens,
685
  max_context_length_tokens,
686
  repetition_penalty,
687
+ top_k,
688
+ validate
689
  ],
690
  outputs=[chatbot, history, attached_file, attached_file_history, status_display],
691
  show_progress=True,
 
700
  fn=add_text, inputs=[chatbot, history, user_input, attached_file, attached_file_history], outputs=[chatbot, history, user_question, attached_file, attached_file_history, image_display , user_input], show_progress=True
701
  )
702
 
703
+ #Validation Button
704
+ # Event-Handler für die Validierung
705
+ validate_btn.click(validate_input, inputs=[user_input_validate, validate], outputs=[status_display, validate, user_input_validate, validate_btn])
706
+ user_input_validate.submit(validate_input, inputs=[user_input_validate, validate], outputs=[status_display, validate, user_input_validate, validate_btn])
707
  predict_event1 = user_input.submit(**transfer_input_args, queue=False,).then(**predict_args)
708
  predict_event2 = submitBtn.click(**transfer_input_args, queue=False,).then(**predict_args)
709
  predict_event3 = upload.upload(file_anzeigen, [upload], [image_display, image_display, attached_file] ) #.then(**predict_args)
 
725
  chatbot_bild,
726
  model_option_zeichnen,
727
  #additional_inputs,
728
+ validate
729
  ],
730
  outputs=[chatbot_bild, status_display2], #[chatbot, history, status_display]
731
  show_progress=True,