Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,68 +1,25 @@
|
|
|
|
|
| 1 |
#
|
| 2 |
-
#
|
| 3 |
-
#
|
|
|
|
|
|
|
|
|
|
| 4 |
#
|
| 5 |
-
import os
|
| 6 |
-
from config import MODEL, INFO, HOST
|
| 7 |
-
import gradio as gr
|
| 8 |
-
|
| 9 |
-
# ----------------------------------------------------
|
| 10 |
-
# Lade dein lokales GGUF‑Modell (llama-cpp-python)
|
| 11 |
-
# ----------------------------------------------------
|
| 12 |
-
from llama_cpp import Llama
|
| 13 |
-
|
| 14 |
-
llm = Llama(
|
| 15 |
-
model_path="./phi-2.Q4_K_M.gguf",
|
| 16 |
-
n_ctx=4096,
|
| 17 |
-
n_threads=4,
|
| 18 |
-
verbose=True
|
| 19 |
-
)
|
| 20 |
-
|
| 21 |
-
# ----------------------------------------------------
|
| 22 |
-
# Ersetzte playground‑Funktion (ohne OpenAI API)
|
| 23 |
-
# ----------------------------------------------------
|
| 24 |
-
async def playground(
|
| 25 |
-
message,
|
| 26 |
-
history,
|
| 27 |
-
num_ctx,
|
| 28 |
-
max_tokens,
|
| 29 |
-
temperature,
|
| 30 |
-
repeat_penalty,
|
| 31 |
-
top_k,
|
| 32 |
-
top_p
|
| 33 |
-
):
|
| 34 |
-
if not isinstance(message, str) or not message.strip():
|
| 35 |
-
yield []
|
| 36 |
-
return
|
| 37 |
|
| 38 |
-
# Chatverlauf in Text umwandeln
|
| 39 |
-
messages = []
|
| 40 |
-
for item in history:
|
| 41 |
-
if isinstance(item, dict) and "role" in item and "content" in item:
|
| 42 |
-
messages.append(f"{item['role']}: {item['content']}")
|
| 43 |
-
messages.append(f"user: {message}")
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
response = ""
|
| 49 |
-
for out in llm(
|
| 50 |
-
prompt,
|
| 51 |
-
max_tokens=int(max_tokens),
|
| 52 |
-
temperature=float(temperature),
|
| 53 |
-
top_k=int(top_k),
|
| 54 |
-
top_p=float(top_p),
|
| 55 |
-
repeat_penalty=float(repeat_penalty),
|
| 56 |
-
stream=True
|
| 57 |
-
):
|
| 58 |
-
token = out["choices"][0]["text"]
|
| 59 |
-
response += token
|
| 60 |
-
yield response
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
# ----------------------------------------------------
|
| 64 |
-
# UI bleibt vollständig unverändert
|
| 65 |
-
# ----------------------------------------------------
|
| 66 |
with gr.Blocks(
|
| 67 |
fill_height=True,
|
| 68 |
fill_width=False
|
|
@@ -70,81 +27,6 @@ with gr.Blocks(
|
|
| 70 |
with gr.Sidebar():
|
| 71 |
gr.HTML(INFO)
|
| 72 |
gr.Markdown("---")
|
| 73 |
-
gr.Markdown("## Modell Parameter")
|
| 74 |
-
num_ctx = gr.Slider(
|
| 75 |
-
minimum=512,
|
| 76 |
-
maximum=8192,
|
| 77 |
-
value=512,
|
| 78 |
-
step=128,
|
| 79 |
-
label="Kontext Länge",
|
| 80 |
-
info="Maximale Kontextfenstergröße (Speicher)"
|
| 81 |
-
)
|
| 82 |
-
gr.Markdown("")
|
| 83 |
-
max_tokens = gr.Slider(
|
| 84 |
-
minimum=512,
|
| 85 |
-
maximum=8192,
|
| 86 |
-
value=512,
|
| 87 |
-
step=128,
|
| 88 |
-
label="Maximale Tokens",
|
| 89 |
-
info="Maximale Anzahl an Tokens, die generiert werden sollen"
|
| 90 |
-
)
|
| 91 |
-
gr.Markdown("")
|
| 92 |
-
temperature = gr.Slider(
|
| 93 |
-
minimum=0.1,
|
| 94 |
-
maximum=1.0,
|
| 95 |
-
value=0.1,
|
| 96 |
-
step=0.1,
|
| 97 |
-
label="Temperatur",
|
| 98 |
-
info="Steuert die Zufälligkeit bei der Textgenerierung"
|
| 99 |
-
)
|
| 100 |
-
gr.Markdown("")
|
| 101 |
-
repeat_penalty = gr.Slider(
|
| 102 |
-
minimum=0.1,
|
| 103 |
-
maximum=2.0,
|
| 104 |
-
value=1.05,
|
| 105 |
-
step=0.1,
|
| 106 |
-
label="Wiederholungsstrafe",
|
| 107 |
-
info="Strafe für wiederholte Tokens"
|
| 108 |
-
)
|
| 109 |
-
gr.Markdown("")
|
| 110 |
-
top_k = gr.Slider(
|
| 111 |
-
minimum=0,
|
| 112 |
-
maximum=100,
|
| 113 |
-
value=50,
|
| 114 |
-
step=1,
|
| 115 |
-
label="Top K",
|
| 116 |
-
info="Anzahl der Top‑Tokens, die berücksichtigt werden sollen"
|
| 117 |
-
)
|
| 118 |
-
gr.Markdown("")
|
| 119 |
-
top_p = gr.Slider(
|
| 120 |
-
minimum=0.0,
|
| 121 |
-
maximum=1.0,
|
| 122 |
-
value=0.1,
|
| 123 |
-
step=0.05,
|
| 124 |
-
label="Top P",
|
| 125 |
-
info="Kumulative Wahrscheinlichkeitsgrenze"
|
| 126 |
-
)
|
| 127 |
-
|
| 128 |
-
gr.ChatInterface(
|
| 129 |
-
fn=playground,
|
| 130 |
-
additional_inputs=[
|
| 131 |
-
num_ctx,
|
| 132 |
-
max_tokens,
|
| 133 |
-
temperature,
|
| 134 |
-
repeat_penalty,
|
| 135 |
-
top_k,
|
| 136 |
-
top_p
|
| 137 |
-
],
|
| 138 |
-
type="messages",
|
| 139 |
-
examples=[
|
| 140 |
-
["Kannst du mir etwas erklären?"],
|
| 141 |
-
["Kannst du mir bei einem Problem helfen?"],
|
| 142 |
-
["Kannst du etwas für mich zusammenfassen?"],
|
| 143 |
-
["Kannst du etwas für mich erstellen?"]
|
| 144 |
-
],
|
| 145 |
-
cache_examples=False,
|
| 146 |
-
show_api=False
|
| 147 |
-
)
|
| 148 |
|
| 149 |
app.launch(
|
| 150 |
server_name=HOST,
|
|
|
|
| 1 |
+
|
| 2 |
#
|
| 3 |
+
# COPYING THIS CODE IS FORBIDDEN!
|
| 4 |
+
# © Copyright Leo Göttlinger(aka. SampleCraft) 2025-2026
|
| 5 |
+
# -S-C- aka. SampleCraft
|
| 6 |
+
# Code by: SampleCraft
|
| 7 |
+
# Map by: Benjamin Hodzic, SampleCraft
|
| 8 |
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
import os
|
| 12 |
+
from config import INFO, HOST
|
| 13 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
#
|
| 16 |
+
# COPYING THIS CODE IS FORBIDDEN!
|
| 17 |
+
# © Copyright Leo Göttlinger(aka. SampleCraft) 2025-2026
|
| 18 |
+
# -S-C- aka. SampleCraft
|
| 19 |
+
# Code by: SampleCraft
|
| 20 |
+
# Map by: Benjamin Hodzic, SampleCraft
|
| 21 |
+
#
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
with gr.Blocks(
|
| 24 |
fill_height=True,
|
| 25 |
fill_width=False
|
|
|
|
| 27 |
with gr.Sidebar():
|
| 28 |
gr.HTML(INFO)
|
| 29 |
gr.Markdown("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
app.launch(
|
| 32 |
server_name=HOST,
|