alexkueck commited on
Commit
97a827b
·
verified ·
1 Parent(s): e378e6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -45
app.py CHANGED
@@ -233,6 +233,18 @@ def rag_chain(prompt, db, k=3):
233
  return neu_prompt
234
 
235
 
 
 
 
 
 
 
 
 
 
 
 
 
236
 
237
  ###################################################
238
  #Prompts mit History erzeugen für verschiednee Modelle
@@ -406,7 +418,7 @@ print ("Start GUI")
406
  with open("custom.css", "r", encoding="utf-8") as f:
407
  customCSS = f.read()
408
 
409
- with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
410
  history = gr.State([])
411
  user_question = gr.State("")
412
 
@@ -495,7 +507,8 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
495
  temperature,
496
  max_length_tokens,
497
  max_context_length_tokens,
498
- repetition_penalty
 
499
  ],
500
  outputs=[ chatbot, status_display], #[ chatbot, history, status_display],
501
  show_progress=True,
@@ -517,12 +530,16 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
517
  predict_event1 = user_input.submit(**transfer_input_args_text, queue=False,).then(**predict_args)
518
  predict_event3 = btn.upload(**transfer_input_args_file,queue=False,).then(**predict_args)
519
  predict_event2 = submitBtn.click(**transfer_input_args_text, queue=False,).then(**predict_args)
 
 
 
 
520
 
521
  cancelBtn.click(
522
  cancel_outputing, [], [status_display],
523
  #cancels=[predict_event1,predict_event2, predict_event3 ]
524
  )
525
- demo.title = "LI-ChatBot"
526
 
527
  demo.queue().launch(debug=True)
528
 
@@ -530,45 +547,3 @@ demo.queue().launch(debug=True)
530
 
531
 
532
 
533
-
534
-
535
-
536
-
537
- """
538
-
539
- description = <strong>Information:</strong> Hier wird ein <strong>Large Language Model (LLM)</strong> mit
540
- <strong>Retrieval Augmented Generation (RAG)</strong> auf <strong>externen Daten</strong> verwendet.\n\n
541
-
542
- css = .toast-wrap { display: none !important }
543
- examples=[['Was ist ChtGPT-4?'],['schreibe ein Python Programm, dass die GPT-4 API aufruft.']]
544
-
545
- additional_inputs = [
546
- gr.Radio(["Aus", "An"], label="RAG - LI Erweiterungen", value = "Aus"),
547
- gr.Radio(["HuggingFace1", "HuggingFace2"], label="Modellauswahl", value = "HuggingFace1"),
548
- gr.Slider(label="Anzahl Vergleichsdokumente", value=3, minimum=1, maximum=10, step=1, interactive=True, info="wie viele Dokumententeile aus dem Vektorstore an den prompt gehängt werden", visible=True),
549
- gr.Slider(label="Temperature", value=0.65, minimum=0.0, maximum=1.0, step=0.05, interactive=True, info="Höhere Werte erzeugen diversere Antworten", visible=True),
550
- gr.Slider(label="Max new tokens", value=1024, minimum=0, maximum=4096, step=64, interactive=True, info="Maximale Anzahl neuer Tokens", visible=True),
551
- gr.Slider(label="Top-p (nucleus sampling)", value=0.6, minimum=0.0, maximum=1, step=0.05, interactive=True, info="Höhere Werte verwenden auch Tokens mit niedrigerer Wahrscheinlichkeit.", visible=True),
552
- gr.Slider(label="Repetition penalty", value=1.2, minimum=1.0, maximum=2.0, step=0.05, interactive=True, info="Strafe für wiederholte Tokens", visible=True)
553
- ]
554
-
555
- chatbot_stream = gr.Chatbot()
556
-
557
- chat_interface_stream = gr.ChatInterface(fn=generate,
558
- additional_inputs = additional_inputs,
559
- additional_inputs_accordion = gr.Accordion(label="Weitere Eingaben...", open=False),
560
- title = "ChatGPT vom LI",
561
- theme="soft",
562
- chatbot=chatbot_stream,
563
- retry_btn="🔄 Wiederholen",
564
- undo_btn="↩️ Letztes löschen",
565
- clear_btn="🗑️ Verlauf löschen",
566
- submit_btn = "Abschicken",
567
- description = description)
568
-
569
- with gr.Blocks() as demo:
570
- with gr.Tab("Chatbot"):
571
- #chatbot_stream.like(vote, None, None)
572
- chat_interface_stream.queue().launch()
573
-
574
- """
 
233
  return neu_prompt
234
 
235
 
236
+
237
+ ########################################
238
+ # Bot- test gegen schädliche Bots die die Anwendung testen...
239
+ # Funktion zur Überprüfung der Benutzereingabe
240
+ # Funktion zur Überprüfung der Eingabe und Aktivierung der Hauptanwendung
241
+ def validate_input(user_input_validate, validate=False):
242
+ user_input_hashed = hash_input(user_input_validate)
243
+ if user_input_hashed == hash_input(ANTI_BOT_PW):
244
+ return "Richtig! Weiter gehts... ", True, gr.Textbox(visible=False), gr.Button(visible=False)
245
+ else:
246
+ 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)
247
+
248
 
249
  ###################################################
250
  #Prompts mit History erzeugen für verschiednee Modelle
 
418
  with open("custom.css", "r", encoding="utf-8") as f:
419
  customCSS = f.read()
420
 
421
+ with gr.Blocks(css=customCSS, theme=themeAlex) as demo:
422
  history = gr.State([])
423
  user_question = gr.State("")
424
 
 
507
  temperature,
508
  max_length_tokens,
509
  max_context_length_tokens,
510
+ repetition_penalty,
511
+ validate
512
  ],
513
  outputs=[ chatbot, status_display], #[ chatbot, history, status_display],
514
  show_progress=True,
 
530
  predict_event1 = user_input.submit(**transfer_input_args_text, queue=False,).then(**predict_args)
531
  predict_event3 = btn.upload(**transfer_input_args_file,queue=False,).then(**predict_args)
532
  predict_event2 = submitBtn.click(**transfer_input_args_text, queue=False,).then(**predict_args)
533
+ #Validation Button
534
+ # Event-Handler für die Validierung
535
+ validate_btn.click(validate_input, inputs=[user_input_validate, validate], outputs=[status_display, validate, user_input_validate, validate_btn])
536
+ user_input_validate.submit(validate_input, inputs=[user_input_validate, validate], outputs=[status_display, validate, user_input_validate, validate_btn])
537
 
538
  cancelBtn.click(
539
  cancel_outputing, [], [status_display],
540
  #cancels=[predict_event1,predict_event2, predict_event3 ]
541
  )
542
+ demo.title = "HH-ChatBot"
543
 
544
  demo.queue().launch(debug=True)
545
 
 
547
 
548
 
549