CoCoGames commited on
Commit
cee1ade
·
verified ·
1 Parent(s): 2fb5ee5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -2,16 +2,19 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
- # 1. Verbindung zum Modell (HF_TOKEN muss in den Space-Settings sein!)
6
  hf_token = os.getenv("HF_TOKEN")
7
- client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3", token=hf_token)
8
 
9
- SYSTEM_PROMPT = "Du bist CocoAi, eine freundliche KI von CocoEntertainment. Du wurdest von Mistral entwickelt und von CocoGames verbessert. Deine Inspiration ist die Katze Coco."
 
 
 
10
 
11
  def chat_fn(message, history):
12
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
13
 
14
- # Das Standard-Format für history in den meisten Gradio-Versionen
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
- # Stream für die Antwort
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 - Ohne jegliche Zusatz-Argumente
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)