marksml commited on
Commit
faefb5a
·
1 Parent(s): f202fcb

get it running again

Browse files
Files changed (1) hide show
  1. app.py +30 -10
app.py CHANGED
@@ -1,15 +1,24 @@
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
  """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
 
 
8
 
9
 
10
  def respond(
11
  message,
12
- history: list[tuple[str, str]],
13
  system_message,
14
  max_tokens,
15
  temperature,
@@ -17,11 +26,21 @@ def respond(
17
  ):
18
  messages = [{"role": "system", "content": system_message}]
19
 
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
  messages.append({"role": "user", "content": message})
27
 
@@ -34,9 +53,10 @@ def respond(
34
  temperature=temperature,
35
  top_p=top_p,
36
  ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
 
40
  yield response
41
 
42
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ import os
4
+
5
+ # Setze deinen Hugging Face API-Token hier
6
+ HF_TOKEN = os.getenv("HF_TOKEN")
7
+
8
+ print("HF_TOKEN:", HF_TOKEN)
9
 
10
  """
11
  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
12
  """
13
+ client = InferenceClient(
14
+ "Qwen/Qwen2.5-72B-Instruct",
15
+ token=HF_TOKEN # Token from Environment Variable or passed directly
16
+ )
17
 
18
 
19
  def respond(
20
  message,
21
+ history: list,
22
  system_message,
23
  max_tokens,
24
  temperature,
 
26
  ):
27
  messages = [{"role": "system", "content": system_message}]
28
 
29
+ # Unterstütze altes Tuple-Format und neues Message-Format
30
+ if history:
31
+ first = history[0]
32
+ if isinstance(first, (list, tuple)):
33
+ for user_msg, assistant_msg in history:
34
+ if user_msg:
35
+ messages.append({"role": "user", "content": user_msg})
36
+ if assistant_msg:
37
+ messages.append({"role": "assistant", "content": assistant_msg})
38
+ elif isinstance(first, dict):
39
+ for item in history:
40
+ role = item.get("role")
41
+ content = item.get("content")
42
+ if role and content:
43
+ messages.append({"role": role, "content": content})
44
 
45
  messages.append({"role": "user", "content": message})
46
 
 
53
  temperature=temperature,
54
  top_p=top_p,
55
  ):
56
+ if message and message.choices and message.choices[0].delta and message.choices[0].delta.content:
57
+ token = message.choices[0].delta.content
58
+ response += str(token)
59
+
60
  yield response
61
 
62