Update app.py
Browse files
app.py
CHANGED
|
@@ -72,8 +72,8 @@ YOUTUBE_URL_3 = "https://www.youtube.com/watch?v=vw-KWfKwvTQ"
|
|
| 72 |
|
| 73 |
################################################
|
| 74 |
#LLM Model mit dem gearbeitet wird
|
| 75 |
-
|
| 76 |
-
MODEL_NAME ="gpt-4"
|
| 77 |
|
| 78 |
#################################################
|
| 79 |
#Funktionen zur Verarbeitung
|
|
@@ -193,6 +193,7 @@ def invoke(openai_api_key, rag_option, prompt):
|
|
| 193 |
#GUI
|
| 194 |
###############################################
|
| 195 |
#Beschreibung oben in GUI
|
|
|
|
| 196 |
description = """<strong>Überblick:</strong> Hier wird ein <strong>Large Language Model (LLM)</strong> mit
|
| 197 |
<strong>Retrieval Augmented Generation (RAG)</strong> auf <strong>externen Daten</strong> demonstriert.\n\n
|
| 198 |
<strong>Genauer:</strong> Folgende externe Daten sind als Beispiel gegeben:
|
|
@@ -204,6 +205,7 @@ description = """<strong>Überblick:</strong> Hier wird ein <strong>Large Langua
|
|
| 204 |
<li>Experimentiere mit Prompts, z.B. Antworte in deutsch, englisch, ..." oder "schreibe ein Python Programm, dass die GPT-4 API aufruft."</li>
|
| 205 |
</ul>\n\n
|
| 206 |
"""
|
|
|
|
| 207 |
#Gradio......
|
| 208 |
gr.close_all()
|
| 209 |
demo = gr.Interface(fn=invoke,
|
|
@@ -214,4 +216,58 @@ demo = gr.Interface(fn=invoke,
|
|
| 214 |
outputs = [gr.Textbox(label = "Completion", lines = 1)],
|
| 215 |
title = "Generative AI - LLM & RAG",
|
| 216 |
description = description)
|
| 217 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
################################################
|
| 74 |
#LLM Model mit dem gearbeitet wird
|
| 75 |
+
MODEL_NAME = "gpt-3.5-turbo-16k"
|
| 76 |
+
#MODEL_NAME ="gpt-4"
|
| 77 |
|
| 78 |
#################################################
|
| 79 |
#Funktionen zur Verarbeitung
|
|
|
|
| 193 |
#GUI
|
| 194 |
###############################################
|
| 195 |
#Beschreibung oben in GUI
|
| 196 |
+
|
| 197 |
description = """<strong>Überblick:</strong> Hier wird ein <strong>Large Language Model (LLM)</strong> mit
|
| 198 |
<strong>Retrieval Augmented Generation (RAG)</strong> auf <strong>externen Daten</strong> demonstriert.\n\n
|
| 199 |
<strong>Genauer:</strong> Folgende externe Daten sind als Beispiel gegeben:
|
|
|
|
| 205 |
<li>Experimentiere mit Prompts, z.B. Antworte in deutsch, englisch, ..." oder "schreibe ein Python Programm, dass die GPT-4 API aufruft."</li>
|
| 206 |
</ul>\n\n
|
| 207 |
"""
|
| 208 |
+
"""
|
| 209 |
#Gradio......
|
| 210 |
gr.close_all()
|
| 211 |
demo = gr.Interface(fn=invoke,
|
|
|
|
| 216 |
outputs = [gr.Textbox(label = "Completion", lines = 1)],
|
| 217 |
title = "Generative AI - LLM & RAG",
|
| 218 |
description = description)
|
| 219 |
+
demo.launch()
|
| 220 |
+
"""
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
###########################################
|
| 224 |
+
title = "LLM mit RAG"
|
| 225 |
+
description = """<strong>Überblick:</strong> Hier wird ein <strong>Large Language Model (LLM)</strong> mit
|
| 226 |
+
<strong>Retrieval Augmented Generation (RAG)</strong> auf <strong>externen Daten</strong> demonstriert.\n\n
|
| 227 |
+
<strong>Genauer:</strong> Folgende externe Daten sind als Beispiel gegeben:
|
| 228 |
+
<a href='""" + YOUTUBE_URL_1 + """'>YouTube</a>, <a href='""" + PDF_URL + """'>PDF</a>, and <a href='""" + WEB_URL + """'>Web.</a> <br>
|
| 229 |
+
Alle neueren Datums!.
|
| 230 |
+
<ul style="list-style-type:square;">
|
| 231 |
+
<li>Setze "Retrieval Augmented Generation" auf "<strong>Off</strong>" und gib einen Prompt ein." Das entspricht <strong> ein LLM nutzen ohne RAG</strong></li>
|
| 232 |
+
<li>Setze "Retrieval Augmented Generation" to "<strong>Chroma</strong>" und gib einen Prompt ein. Das <strong>LLM mit RAG</strong> weiß auch Antworten zu aktuellen Themen aus den angefügten Datenquellen</li>
|
| 233 |
+
<li>Experimentiere mit Prompts, z.B. Antworte in deutsch, englisch, ..." oder "schreibe ein Python Programm, dass die GPT-4 API aufruft."</li>
|
| 234 |
+
</ul>\n\n
|
| 235 |
+
"""
|
| 236 |
+
css = """.toast-wrap { display: none !important } """
|
| 237 |
+
examples=[['Was ist ChtGPT-4?'],['schreibe ein Python Programm, dass die GPT-4 API aufruft.']]
|
| 238 |
+
|
| 239 |
+
def vote(data: gr.LikeData):
|
| 240 |
+
if data.liked: print("You upvoted this response: " + data.value)
|
| 241 |
+
else: print("You downvoted this response: " + data.value)
|
| 242 |
+
|
| 243 |
+
additional_inputs = [
|
| 244 |
+
gr.Textbox(label = "OpenAI API Key", value = "sk-", lines = 1),
|
| 245 |
+
gr.Radio(["Off", "Chroma"], label="Retrieval Augmented Generation", value = "Off"),
|
| 246 |
+
gr.Slider(label="Temperature", value=0.9, minimum=0.0, maximum=1.0, step=0.05, interactive=True, info="Höhere Werte erzeugen diversere Antworten"),
|
| 247 |
+
gr.Slider(label="Max new tokens", value=256, minimum=0, maximum=4096, step=64, interactive=True, info="Maximale Anzahl neuer Tokens"),
|
| 248 |
+
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."),
|
| 249 |
+
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")
|
| 250 |
+
]
|
| 251 |
+
|
| 252 |
+
chatbot_stream = gr.Chatbot(avatar_images=(
|
| 253 |
+
"https://drive.google.com/uc?id=18xKoNOHN15H_qmGhK__VKnGjKjirrquW",
|
| 254 |
+
"https://drive.google.com/uc?id=1tfELAQW_VbPCy6QTRbexRlwAEYo8rSSv"
|
| 255 |
+
), bubble_full_width = False)
|
| 256 |
+
|
| 257 |
+
chat_interface_stream = gr.ChatInterface(
|
| 258 |
+
invoke,
|
| 259 |
+
title=title,
|
| 260 |
+
description=description,
|
| 261 |
+
chatbot=chatbot_stream,
|
| 262 |
+
css=css,
|
| 263 |
+
examples=examples,
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
with gr.Blocks() as demo:
|
| 267 |
+
with gr.Tab("General LLM"):
|
| 268 |
+
chatbot_stream.like(vote, None, None)
|
| 269 |
+
chat_interface_stream.render()
|
| 270 |
+
with gr.Row():
|
| 271 |
+
gr.Radio(["Off", "Chroma"], label="Retrieval Augmented Generation", value = "Off"),
|
| 272 |
+
|
| 273 |
+
demo.queue(concurrency_count=75, max_size=100).launch(debug=True)
|