Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,90 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
# Initialisierung des Inference-Clients
|
| 5 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
# Funktion, die die Chat-Antwort generiert
|
| 9 |
-
def respond(
|
| 10 |
-
message,
|
| 11 |
-
history: list[tuple[str, str]],
|
| 12 |
-
system_message,
|
| 13 |
-
max_tokens,
|
| 14 |
-
temperature,
|
| 15 |
-
top_p,
|
| 16 |
-
):
|
| 17 |
-
messages = [{"role": "system", "content": system_message}]
|
| 18 |
-
|
| 19 |
-
# Historie hinzufügen
|
| 20 |
-
for val in history:
|
| 21 |
-
if val[0]:
|
| 22 |
-
messages.append({"role": "user", "content": val[0]})
|
| 23 |
-
if val[1]:
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
-
|
| 26 |
-
# Benutzer-Nachricht hinzufügen
|
| 27 |
-
messages.append({"role": "user", "content": message})
|
| 28 |
-
|
| 29 |
-
response = ""
|
| 30 |
-
|
| 31 |
-
# Stream-Antwort verarbeiten
|
| 32 |
-
for message in client.chat_completion(
|
| 33 |
-
messages,
|
| 34 |
-
max_tokens=max_tokens,
|
| 35 |
-
stream=True,
|
| 36 |
-
temperature=temperature,
|
| 37 |
-
top_p=top_p,
|
| 38 |
-
):
|
| 39 |
-
token = message.choices[0].delta.content
|
| 40 |
-
response += token
|
| 41 |
-
yield response
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
# Funktion zur Bearbeitung des Prompts vor dem Senden
|
| 45 |
-
def edit_prompt(original_prompt):
|
| 46 |
-
# Hier könnte man Logik einfügen, um den Prompt automatisch anzupassen
|
| 47 |
-
return original_prompt # Zurzeit unverändert zurückgeben
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
# Gradio UI anpassen
|
| 51 |
-
def chat_interface_wrapper(
|
| 52 |
-
message,
|
| 53 |
-
history,
|
| 54 |
-
system_message,
|
| 55 |
-
max_tokens,
|
| 56 |
-
temperature,
|
| 57 |
-
top_p,
|
| 58 |
-
):
|
| 59 |
-
# Möglichkeit, den Prompt vor dem Senden zu bearbeiten
|
| 60 |
-
message = edit_prompt(message)
|
| 61 |
-
return respond(message, history, system_message, max_tokens, temperature, top_p)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
# Gradio Chat Interface mit zusätzlichen Eingaben
|
| 65 |
-
demo = gr.ChatInterface(
|
| 66 |
-
chat_interface_wrapper,
|
| 67 |
-
additional_inputs=[
|
| 68 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 69 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 70 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 71 |
-
gr.Slider(
|
| 72 |
-
minimum=0.1,
|
| 73 |
-
maximum=1.0,
|
| 74 |
-
value=0.95,
|
| 75 |
-
step=0.05,
|
| 76 |
-
label="Top-p (nucleus sampling)",
|
| 77 |
-
),
|
| 78 |
-
],
|
| 79 |
-
)
|
| 80 |
-
|
| 81 |
-
if __name__ == "__main__":
|
| 82 |
-
demo.launch()
|
| 83 |
-
|
| 84 |
-
'''
|
| 85 |
-
import gradio as gr
|
| 86 |
-
from huggingface_hub import InferenceClient
|
| 87 |
-
|
| 88 |
"""
|
| 89 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 90 |
"""
|
|
@@ -145,5 +61,4 @@ demo = gr.ChatInterface(
|
|
| 145 |
|
| 146 |
|
| 147 |
if __name__ == "__main__":
|
| 148 |
-
demo.launch()
|
| 149 |
-
'''
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
"""
|
| 5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
"""
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|
| 64 |
+
demo.launch()
|
|
|