MadT21 commited on
Commit
69c0780
·
verified ·
1 Parent(s): 2e89ff8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -45
app.py CHANGED
@@ -36,52 +36,33 @@ def respond(
36
 
37
  response = ""
38
 
39
- if use_local_model:
40
- print("[MODE] local")
41
- from transformers import pipeline
42
- if pipe is None:
43
- pipe = pipeline("text-generation", model="microsoft/Phi-3-mini-4k-instruct")
44
 
45
- prompt = "\n".join([f"{m['role']}: {m['content']}" for m in messages])
46
-
47
- outputs = pipe(
48
- prompt,
49
- max_new_tokens=max_tokens,
50
- do_sample=True,
51
- temperature=temperature,
52
- top_p=top_p,
53
- )
54
-
55
- response = outputs[0]["generated_text"][len(prompt):]
56
- yield response.strip()
57
-
58
- else:
59
- print("[MODE] api")
60
- token_value = None
61
- if hf_token and getattr(hf_token, "token", None):
62
- token_value = hf_token.token
63
- elif os.environ.get("HF_TOKEN"):
64
- token_value = os.environ.get("HF_TOKEN")
65
-
66
- if not token_value:
67
- yield "⚠️ Please log in with your Hugging Face account or set HF_TOKEN in environment."
68
- return
69
-
70
- client = InferenceClient(token=os.environ["HF_TOKEN"], model="openai/gpt-oss-20b")
71
-
72
- for chunk in client.chat_completion(
73
- messages,
74
- max_tokens=max_tokens,
75
- stream=True,
76
- temperature=temperature,
77
- top_p=top_p,
78
- ):
79
- choices = chunk.choices
80
- token = ""
81
- if len(choices) and choices[0].delta.content:
82
- token = choices[0].delta.content
83
- response += token
84
- yield response
85
 
86
  # --- Chat Interface ---
87
  chatbot = gr.ChatInterface(
 
36
 
37
  response = ""
38
 
 
 
 
 
 
39
 
40
+ print("[MODE] api")
41
+ token_value = None
42
+ if hf_token and getattr(hf_token, "token", None):
43
+ token_value = hf_token.token
44
+ elif os.environ.get("HF_TOKEN"):
45
+ token_value = os.environ.get("HF_TOKEN")
46
+
47
+ if not token_value:
48
+ yield "⚠️ Please log in with your Hugging Face account or set HF_TOKEN in environment."
49
+ return
50
+
51
+ client = InferenceClient(token=os.environ["HF_TOKEN"], model="openai/gpt-oss-20b")
52
+
53
+ for chunk in client.chat_completion(
54
+ messages,
55
+ max_tokens=max_tokens,
56
+ stream=True,
57
+ temperature=temperature,
58
+ top_p=top_p,
59
+ ):
60
+ choices = chunk.choices
61
+ token = ""
62
+ if len(choices) and choices[0].delta.content:
63
+ token = choices[0].delta.content
64
+ response += token
65
+ yield response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  # --- Chat Interface ---
68
  chatbot = gr.ChatInterface(