Spaces:
Running
Running
Feature(LLMLingua): changing the style
Browse files
app.py
CHANGED
@@ -52,7 +52,6 @@ custom_css = """
|
|
52 |
|
53 |
def compress_prompt(context, instruction, question, ratio, target_token):
|
54 |
context, instruction, question = context.replace("\\n", "\n"), instruction.replace("\\n", "\n"), question.replace("\\n", "\n")
|
55 |
-
print(context)
|
56 |
compressed_prompt = llm_lingua.compress_prompt(context.split("\n\n"), instruction, question, float(ratio), float(target_token))
|
57 |
|
58 |
return [compressed_prompt[key] for key in ["compressed_prompt", "origin_tokens", "compressed_tokens", "ratio", "saving"]]
|
@@ -62,7 +61,7 @@ with gr.Blocks(css=custom_css) as iface:
|
|
62 |
gr.Markdown(INTRO)
|
63 |
|
64 |
with gr.Row():
|
65 |
-
with gr.Column(elem_id="
|
66 |
with gr.Tab('Prompts'):
|
67 |
instruction = gr.Textbox(
|
68 |
label="Instruction",
|
@@ -79,25 +78,19 @@ with gr.Blocks(css=custom_css) as iface:
|
|
79 |
lines=1,
|
80 |
value="",
|
81 |
)
|
|
|
82 |
with gr.Tab('Compression Target'):
|
83 |
-
ratio = gr.Textbox(
|
84 |
-
label="Compression Ratio",
|
85 |
-
value=0.5,
|
86 |
-
)
|
87 |
target_token = gr.Textbox(
|
88 |
-
label="Target Token",
|
89 |
-
value
|
|
|
|
|
|
|
|
|
90 |
)
|
91 |
|
92 |
gen_button = gr.Button(value="Compress Prompt!", variant="primary")
|
93 |
|
94 |
-
# with gr.Tab('Results'):
|
95 |
-
# results = gr.Gallery(
|
96 |
-
# show_label=False,
|
97 |
-
# object_fit="contain",
|
98 |
-
# columns=4
|
99 |
-
# )
|
100 |
-
|
101 |
with gr.Row():
|
102 |
with gr.Column(elem_id="Results"):
|
103 |
with gr.Tab('Compressed Prompts'):
|
@@ -105,6 +98,8 @@ with gr.Blocks(css=custom_css) as iface:
|
|
105 |
label="compressed_prompt",
|
106 |
lines=5,
|
107 |
)
|
|
|
|
|
108 |
with gr.Tab('Saving'):
|
109 |
origin_tokens = gr.Textbox(
|
110 |
label="The tokens number of original prompt",
|
|
|
52 |
|
53 |
def compress_prompt(context, instruction, question, ratio, target_token):
|
54 |
context, instruction, question = context.replace("\\n", "\n"), instruction.replace("\\n", "\n"), question.replace("\\n", "\n")
|
|
|
55 |
compressed_prompt = llm_lingua.compress_prompt(context.split("\n\n"), instruction, question, float(ratio), float(target_token))
|
56 |
|
57 |
return [compressed_prompt[key] for key in ["compressed_prompt", "origin_tokens", "compressed_tokens", "ratio", "saving"]]
|
|
|
61 |
gr.Markdown(INTRO)
|
62 |
|
63 |
with gr.Row():
|
64 |
+
with gr.Column(elem_id="prompt"):
|
65 |
with gr.Tab('Prompts'):
|
66 |
instruction = gr.Textbox(
|
67 |
label="Instruction",
|
|
|
78 |
lines=1,
|
79 |
value="",
|
80 |
)
|
81 |
+
with gr.Column(elem_id="params"):
|
82 |
with gr.Tab('Compression Target'):
|
|
|
|
|
|
|
|
|
83 |
target_token = gr.Textbox(
|
84 |
+
label="Target Token (To use this, set Compression Ratio to 0)",
|
85 |
+
value=200,
|
86 |
+
)
|
87 |
+
ratio = gr.Textbox(
|
88 |
+
label="Compression Ratio (To use this, set Target Token to -1)",
|
89 |
+
value=0,
|
90 |
)
|
91 |
|
92 |
gen_button = gr.Button(value="Compress Prompt!", variant="primary")
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
with gr.Row():
|
95 |
with gr.Column(elem_id="Results"):
|
96 |
with gr.Tab('Compressed Prompts'):
|
|
|
98 |
label="compressed_prompt",
|
99 |
lines=5,
|
100 |
)
|
101 |
+
with gr.Row():
|
102 |
+
with gr.Column(elem_id="Results_2"):
|
103 |
with gr.Tab('Saving'):
|
104 |
origin_tokens = gr.Textbox(
|
105 |
label="The tokens number of original prompt",
|