Andrew Tanny Liem commited on
Commit ·
4b0a93e
1
Parent(s): 17cc328
update app.py
Browse files
app.py
CHANGED
|
@@ -69,10 +69,19 @@ def user_submit(user_message: str, history: List[Tuple[str, str]]):
|
|
| 69 |
return "", history
|
| 70 |
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def bot_reply(history: List[Tuple[str, str]], temperature: float = 0.7, top_p: float = 0.95, max_tokens: int = 512, hf_token: gr.OAuthToken = None):
|
| 73 |
last_user = history[-1][0] if history else ""
|
| 74 |
messages = _build_messages(history[:-1], last_user)
|
| 75 |
-
client = InferenceClient(token=(hf_token
|
| 76 |
|
| 77 |
acc = ""
|
| 78 |
for event in client.chat_completion(
|
|
@@ -99,7 +108,7 @@ def summarize(history: List[Tuple[str, str]], hf_token: gr.OAuthToken = None):
|
|
| 99 |
if not transcript.strip():
|
| 100 |
return {"note": "No conversation yet. Ask Maya some questions first."}
|
| 101 |
|
| 102 |
-
client = InferenceClient(token=(hf_token
|
| 103 |
messages = [
|
| 104 |
{"role": "system", "content": SUMMARY_SYSTEM_PROMPT},
|
| 105 |
{
|
|
@@ -126,9 +135,13 @@ def summarize(history: List[Tuple[str, str]], hf_token: gr.OAuthToken = None):
|
|
| 126 |
|
| 127 |
|
| 128 |
with gr.Blocks(title="Maya – Klinik Owner (Role-Play)") as demo:
|
| 129 |
-
# Top login section
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
gr.Markdown("Model: `" + HF_MODEL + "`")
|
| 133 |
|
| 134 |
gr.Markdown(
|
|
|
|
| 69 |
return "", history
|
| 70 |
|
| 71 |
|
| 72 |
+
def _oauth_or_env_token(hf_token: gr.OAuthToken | None):
|
| 73 |
+
try:
|
| 74 |
+
if hf_token and getattr(hf_token, "token", None):
|
| 75 |
+
return hf_token.token
|
| 76 |
+
except Exception:
|
| 77 |
+
pass
|
| 78 |
+
return os.getenv("HF_TOKEN")
|
| 79 |
+
|
| 80 |
+
|
| 81 |
def bot_reply(history: List[Tuple[str, str]], temperature: float = 0.7, top_p: float = 0.95, max_tokens: int = 512, hf_token: gr.OAuthToken = None):
|
| 82 |
last_user = history[-1][0] if history else ""
|
| 83 |
messages = _build_messages(history[:-1], last_user)
|
| 84 |
+
client = InferenceClient(token=_oauth_or_env_token(hf_token), model=HF_MODEL)
|
| 85 |
|
| 86 |
acc = ""
|
| 87 |
for event in client.chat_completion(
|
|
|
|
| 108 |
if not transcript.strip():
|
| 109 |
return {"note": "No conversation yet. Ask Maya some questions first."}
|
| 110 |
|
| 111 |
+
client = InferenceClient(token=_oauth_or_env_token(hf_token), model=HF_MODEL)
|
| 112 |
messages = [
|
| 113 |
{"role": "system", "content": SUMMARY_SYSTEM_PROMPT},
|
| 114 |
{
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
with gr.Blocks(title="Maya – Klinik Owner (Role-Play)") as demo:
|
| 138 |
+
# Top login section: enable OAuth on Spaces, skip locally
|
| 139 |
+
is_space = bool(os.getenv("SPACE_ID") or os.getenv("SYSTEM") == "spaces")
|
| 140 |
+
if is_space:
|
| 141 |
+
gr.Markdown("## Sign in to use the model")
|
| 142 |
+
gr.LoginButton()
|
| 143 |
+
else:
|
| 144 |
+
gr.Markdown("Tip: set env var `HF_TOKEN` for local use.")
|
| 145 |
gr.Markdown("Model: `" + HF_MODEL + "`")
|
| 146 |
|
| 147 |
gr.Markdown(
|