Update app.py
Browse files
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 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 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(
|