Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import gradio as gr
|
| 3 |
+
df = pd.read_json("data.json")
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def filter_data(x, language):
|
| 7 |
+
language_filtered_df = df[df['language'] == language]
|
| 8 |
+
lower_bound = x
|
| 9 |
+
upper_bound = x + 0.1
|
| 10 |
+
mask = (language_filtered_df['prev_nn_sim'] >= lower_bound) & (language_filtered_df['prev_nn_sim'] < upper_bound)
|
| 11 |
+
filtered_df = language_filtered_df.loc[mask, ["prompt", "prev_nn_prompt", "prev_nn_sim"]]
|
| 12 |
+
filtered_df = filtered_df.sort_values(by="prev_nn_sim", ascending=True)
|
| 13 |
+
return filtered_df
|
| 14 |
+
|
| 15 |
+
custom_css = """
|
| 16 |
+
#my_table table {
|
| 17 |
+
table-layout: fixed;
|
| 18 |
+
width: 100%; /* or a fixed width like 700px */
|
| 19 |
+
}
|
| 20 |
+
#my_table table th,
|
| 21 |
+
#my_table table td {
|
| 22 |
+
/* Force wrapping within cells: */
|
| 23 |
+
white-space: normal;
|
| 24 |
+
word-wrap: break-word;
|
| 25 |
+
overflow-wrap: break-word;
|
| 26 |
+
/* Example fixed width for all columns (or use nth-child to target individually): */
|
| 27 |
+
width: 200px;
|
| 28 |
+
}
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 32 |
+
gr.Markdown("## Prompt Freshness Nearest Neighbor")
|
| 33 |
+
gr.Markdown("### Select a similarity threshold (x) and a language to see the prompts that are within 0.1 of x. ")
|
| 34 |
+
gr.Markdown("The nearest neighbor prompt is the prompt that is most similar to the original prompt that appears at a previous time step.")
|
| 35 |
+
|
| 36 |
+
dropdown = gr.Dropdown(
|
| 37 |
+
choices=[round((i + 3) * 0.1, 1) for i in range(7)],
|
| 38 |
+
value=0.7,
|
| 39 |
+
label="Select a similarity threshold (x)"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
language_dropdown = gr.Dropdown(
|
| 43 |
+
choices=df['language'].unique().tolist(),
|
| 44 |
+
value="English",
|
| 45 |
+
label="Select a language"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
output = gr.DataFrame(
|
| 49 |
+
label="Filtered Data",
|
| 50 |
+
headers=["Prompt", "Nearest Neighbor Prompt", "Nearest Neighbor Similarity"],
|
| 51 |
+
elem_id="my_table"
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
dropdown.change(fn=filter_data, inputs=[dropdown, language_dropdown], outputs=output)
|
| 55 |
+
language_dropdown.change(fn=filter_data, inputs=[dropdown, language_dropdown], outputs=output)
|
| 56 |
+
|
| 57 |
+
demo.launch(share=True)
|