Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -99,7 +99,7 @@ def predict_comprehensive(
|
|
| 99 |
text2: str = "",
|
| 100 |
top_k: int = 0,
|
| 101 |
include_embeddings: bool = False,
|
| 102 |
-
|
| 103 |
include_unconditional: bool = False,
|
| 104 |
use_logprobs: bool = True
|
| 105 |
):
|
|
@@ -176,15 +176,13 @@ def predict_comprehensive(
|
|
| 176 |
"first_10_tokens_sample": embeddings_cache[:10, :10].tolist() if embeddings_cache is not None else None
|
| 177 |
}
|
| 178 |
|
| 179 |
-
#
|
| 180 |
-
if
|
| 181 |
if umap_projections_cache is not None:
|
| 182 |
-
|
| 183 |
-
result["pca"] = {
|
| 184 |
-
"projections": umap_projections_cache.tolist(),
|
| 185 |
-
"explained_variance_ratio": [0.0, 0.0], # Placeholder; UMAP has no variance ratio
|
| 186 |
"method": "umap",
|
| 187 |
"umap_params": umap_params,
|
|
|
|
| 188 |
}
|
| 189 |
|
| 190 |
return result
|
|
@@ -219,12 +217,12 @@ with gr.Blocks(title="Token Probability Visualization API") as demo:
|
|
| 219 |
gr.Markdown("""
|
| 220 |
# Token Probability Visualization API
|
| 221 |
|
| 222 |
-
This API provides token probabilities, embeddings, and
|
| 223 |
Model: `openai-community/gpt2`
|
| 224 |
""")
|
| 225 |
|
| 226 |
with gr.Tab("Comprehensive API"):
|
| 227 |
-
gr.Markdown("### Get token probabilities with optional embeddings and
|
| 228 |
|
| 229 |
with gr.Row():
|
| 230 |
with gr.Column():
|
|
@@ -242,7 +240,7 @@ with gr.Blocks(title="Token Probability Visualization API") as demo:
|
|
| 242 |
with gr.Row():
|
| 243 |
top_k_slider = gr.Slider(0, 200, step=1, value=20, label="Top-K tokens")
|
| 244 |
include_embeddings = gr.Checkbox(False, label="Include Embeddings Sample")
|
| 245 |
-
|
| 246 |
include_unconditional = gr.Checkbox(True, label="Include Unconditional")
|
| 247 |
use_logprobs = gr.Checkbox(True, label="Include Log Probabilities")
|
| 248 |
|
|
@@ -253,8 +251,8 @@ with gr.Blocks(title="Token Probability Visualization API") as demo:
|
|
| 253 |
|
| 254 |
predict_btn.click(
|
| 255 |
fn=predict_comprehensive,
|
| 256 |
-
inputs=[text_input, text2_input, top_k_slider, include_embeddings,
|
| 257 |
-
|
| 258 |
outputs=output_json,
|
| 259 |
api_name="predict"
|
| 260 |
)
|
|
|
|
| 99 |
text2: str = "",
|
| 100 |
top_k: int = 0,
|
| 101 |
include_embeddings: bool = False,
|
| 102 |
+
include_layout: bool = False,
|
| 103 |
include_unconditional: bool = False,
|
| 104 |
use_logprobs: bool = True
|
| 105 |
):
|
|
|
|
| 176 |
"first_10_tokens_sample": embeddings_cache[:10, :10].tolist() if embeddings_cache is not None else None
|
| 177 |
}
|
| 178 |
|
| 179 |
+
# UMAP layout if requested
|
| 180 |
+
if include_layout:
|
| 181 |
if umap_projections_cache is not None:
|
| 182 |
+
result["layout"] = {
|
|
|
|
|
|
|
|
|
|
| 183 |
"method": "umap",
|
| 184 |
"umap_params": umap_params,
|
| 185 |
+
"projections": umap_projections_cache.tolist(),
|
| 186 |
}
|
| 187 |
|
| 188 |
return result
|
|
|
|
| 217 |
gr.Markdown("""
|
| 218 |
# Token Probability Visualization API
|
| 219 |
|
| 220 |
+
This API provides token probabilities, embeddings, and a precomputed UMAP layout for visualization.
|
| 221 |
Model: `openai-community/gpt2`
|
| 222 |
""")
|
| 223 |
|
| 224 |
with gr.Tab("Comprehensive API"):
|
| 225 |
+
gr.Markdown("### Get token probabilities with optional embeddings and 2D layout")
|
| 226 |
|
| 227 |
with gr.Row():
|
| 228 |
with gr.Column():
|
|
|
|
| 240 |
with gr.Row():
|
| 241 |
top_k_slider = gr.Slider(0, 200, step=1, value=20, label="Top-K tokens")
|
| 242 |
include_embeddings = gr.Checkbox(False, label="Include Embeddings Sample")
|
| 243 |
+
include_layout = gr.Checkbox(False, label="Include 2D Layout (UMAP)")
|
| 244 |
include_unconditional = gr.Checkbox(True, label="Include Unconditional")
|
| 245 |
use_logprobs = gr.Checkbox(True, label="Include Log Probabilities")
|
| 246 |
|
|
|
|
| 251 |
|
| 252 |
predict_btn.click(
|
| 253 |
fn=predict_comprehensive,
|
| 254 |
+
inputs=[text_input, text2_input, top_k_slider, include_embeddings,
|
| 255 |
+
include_layout, include_unconditional, use_logprobs],
|
| 256 |
outputs=output_json,
|
| 257 |
api_name="predict"
|
| 258 |
)
|