Spaces:
Sleeping
Sleeping
Raphael Glon
commited on
wip
Browse filesSigned-off-by: Raphael Glon <[email protected]>
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import spaces
|
|
| 4 |
|
| 5 |
import logging
|
| 6 |
import os
|
|
|
|
| 7 |
import threading
|
| 8 |
from typing import List, Tuple, Dict
|
| 9 |
|
|
@@ -22,6 +23,8 @@ MAX_NEW_TOKENS = 256
|
|
| 22 |
TEMPERATURE = 0.7
|
| 23 |
TOP_P = 0.95
|
| 24 |
|
|
|
|
|
|
|
| 25 |
# --- Silent Hub auth via env/Space Secret (no UI) ---
|
| 26 |
HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
|
| 27 |
if HF_TOKEN:
|
|
@@ -111,14 +114,25 @@ def generate_stream(message: str, history: List[Tuple[str, str]]):
|
|
| 111 |
thread = threading.Thread(target=_model.generate, kwargs=gen_kwargs)
|
| 112 |
thread.start()
|
| 113 |
|
|
|
|
| 114 |
output = ""
|
| 115 |
for new_text in streamer:
|
| 116 |
output += new_text
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
|
| 121 |
-
with gr.Blocks(title="
|
| 122 |
gr.Markdown(
|
| 123 |
"""
|
| 124 |
# Chat
|
|
|
|
| 4 |
|
| 5 |
import logging
|
| 6 |
import os
|
| 7 |
+
import re
|
| 8 |
import threading
|
| 9 |
from typing import List, Tuple, Dict
|
| 10 |
|
|
|
|
| 23 |
TEMPERATURE = 0.7
|
| 24 |
TOP_P = 0.95
|
| 25 |
|
| 26 |
+
ANALYSIS_PATTERN = analysis_match = re.compile(r'^(.*)assistantfinal', flags=re.DOTALL)
|
| 27 |
+
|
| 28 |
# --- Silent Hub auth via env/Space Secret (no UI) ---
|
| 29 |
HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
|
| 30 |
if HF_TOKEN:
|
|
|
|
| 114 |
thread = threading.Thread(target=_model.generate, kwargs=gen_kwargs)
|
| 115 |
thread.start()
|
| 116 |
|
| 117 |
+
analysis = ""
|
| 118 |
output = ""
|
| 119 |
for new_text in streamer:
|
| 120 |
output += new_text
|
| 121 |
+
if not analysis:
|
| 122 |
+
m = ANALYSIS_PATTERN.match(output)
|
| 123 |
+
if m:
|
| 124 |
+
analysis = re.sub(r'^analysis\s*', '', m.group(1))
|
| 125 |
+
output = ""
|
| 126 |
+
|
| 127 |
+
LOG.info("NEW TEXT: %s, OUTPUT: %s", new_text, output.encode())
|
| 128 |
+
if not analysis:
|
| 129 |
+
answer = f"Analysis:\n{output}"
|
| 130 |
+
else:
|
| 131 |
+
answer = f"Analysis:\n{analysis}\nAnswer:\n{output}"
|
| 132 |
+
yield answer
|
| 133 |
|
| 134 |
|
| 135 |
+
with gr.Blocks(title="OpenAI GPT-OSS 20B Chat") as demo:
|
| 136 |
gr.Markdown(
|
| 137 |
"""
|
| 138 |
# Chat
|