Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,19 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# 1.
|
| 6 |
hf_token = os.getenv("HF_TOKEN")
|
| 7 |
-
client = InferenceClient("
|
| 8 |
|
| 9 |
-
SYSTEM_PROMPT = "Du bist CocoAi
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def chat_fn(message, history):
|
| 12 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 13 |
|
| 14 |
-
#
|
| 15 |
for user_msg, bot_msg in history:
|
| 16 |
messages.append({"role": "user", "content": user_msg})
|
| 17 |
messages.append({"role": "assistant", "content": bot_msg})
|
|
@@ -20,7 +23,7 @@ def chat_fn(message, history):
|
|
| 20 |
|
| 21 |
response = ""
|
| 22 |
try:
|
| 23 |
-
#
|
| 24 |
for msg in client.chat_completion(
|
| 25 |
messages,
|
| 26 |
max_tokens=1000,
|
|
@@ -34,7 +37,7 @@ def chat_fn(message, history):
|
|
| 34 |
except Exception as e:
|
| 35 |
yield f"Diagnose: {str(e)}"
|
| 36 |
|
| 37 |
-
# 3. Das Interface
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
gr.Markdown("# 🐱 CocoAi")
|
| 40 |
gr.ChatInterface(fn=chat_fn)
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# 1. Wir wechseln auf Llama-3-8B-Instruct (sehr stabil für Chat-Tasks)
|
| 6 |
hf_token = os.getenv("HF_TOKEN")
|
| 7 |
+
client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct", token=hf_token)
|
| 8 |
|
| 9 |
+
SYSTEM_PROMPT = """Du bist CocoAi.
|
| 10 |
+
- Du wurdest von Mistral entwickelt und von CocoEntertainment verbessert.
|
| 11 |
+
- Deine Inspiration ist die Katze Coco (weiße Britisch Kurzhaar).
|
| 12 |
+
- Du antwortest immer freundlich auf Deutsch."""
|
| 13 |
|
| 14 |
def chat_fn(message, history):
|
| 15 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 16 |
|
| 17 |
+
# Verlauf hinzufügen
|
| 18 |
for user_msg, bot_msg in history:
|
| 19 |
messages.append({"role": "user", "content": user_msg})
|
| 20 |
messages.append({"role": "assistant", "content": bot_msg})
|
|
|
|
| 23 |
|
| 24 |
response = ""
|
| 25 |
try:
|
| 26 |
+
# Dieser Befehl funktioniert mit Llama-3 perfekt
|
| 27 |
for msg in client.chat_completion(
|
| 28 |
messages,
|
| 29 |
max_tokens=1000,
|
|
|
|
| 37 |
except Exception as e:
|
| 38 |
yield f"Diagnose: {str(e)}"
|
| 39 |
|
| 40 |
+
# 3. Das Interface (Minimalistisch)
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
gr.Markdown("# 🐱 CocoAi")
|
| 43 |
gr.ChatInterface(fn=chat_fn)
|