Spaces:
Runtime error
Runtime error
JerryLiJinyi
commited on
Commit
•
8f819b8
1
Parent(s):
0d6d320
Upload app.py
Browse files
app.py
CHANGED
@@ -21,11 +21,16 @@ def compressit(original_text, compressor1, ratio, maxlength):
|
|
21 |
else:
|
22 |
compressor = PromptCompressor(type='SCCompressor', lang='en', model='gpt2', device='cpu')
|
23 |
|
24 |
-
if compressor1
|
25 |
-
compressed_prompt = compressor.compressgo(original_prompt=original_text, ratio=float(ratio)
|
26 |
else:
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
|
31 |
demo = gr.Interface(
|
@@ -36,10 +41,11 @@ demo = gr.Interface(
|
|
36 |
["Selective Context", "LLMLingua", "LongLLMLingua", "SCRL", "KiS"], label="compressor", info="Choose your compressor here. \n Currently, we cannot support the online demo for LLMLingua and LongLLMLingua due to the Huggingface Token issue."
|
37 |
),
|
38 |
gr.Textbox(lines=1, placeholder="Enter the compression ratio here...", info="Ratio only works for Selective Context, LLMLingua and LongLLMLingua."),
|
39 |
-
gr.Textbox(lines=1, placeholder="Enter the max_length parameter if you are using SCRL or KiS", label="max_length", info="If you are using SCRL or KiS, fill in the parameter, if not, just ignore this.\n Hint: For SCRL, max_length should be shorter than the lenght of original prompt; For KiS, max_length should be longer than it.")
|
40 |
],
|
41 |
outputs=[
|
42 |
-
gr.Textbox(lines=1, info="Please wait patiently when proceeding it may take more than 2 minutes to generate since we are using CPUs for free.")
|
|
|
43 |
]
|
44 |
)
|
45 |
|
|
|
21 |
else:
|
22 |
compressor = PromptCompressor(type='SCCompressor', lang='en', model='gpt2', device='cpu')
|
23 |
|
24 |
+
if compressor1 == "Selective Context":
|
25 |
+
compressed_prompt = compressor.compressgo(original_prompt=original_text, ratio=float(ratio))
|
26 |
else:
|
27 |
+
if maxlength:
|
28 |
+
compressed_prompt = compressor.compressgo(original_prompt=original_text, ratio=float(ratio), max_length=int(maxlength))
|
29 |
+
else:
|
30 |
+
gr.Warning("max_length is needed for this type of compressor. Please fill in and try again.")
|
31 |
+
return "max_length is missing."
|
32 |
+
gr.Warning("The prompt is generating, please wait patiently as it may take a long time to generate during busy hours.")
|
33 |
+
return compressed_prompt["compressed_prompt"], compressed_prompt["ratio"]
|
34 |
|
35 |
|
36 |
demo = gr.Interface(
|
|
|
41 |
["Selective Context", "LLMLingua", "LongLLMLingua", "SCRL", "KiS"], label="compressor", info="Choose your compressor here. \n Currently, we cannot support the online demo for LLMLingua and LongLLMLingua due to the Huggingface Token issue."
|
42 |
),
|
43 |
gr.Textbox(lines=1, placeholder="Enter the compression ratio here...", info="Ratio only works for Selective Context, LLMLingua and LongLLMLingua."),
|
44 |
+
gr.Textbox(lines=1, placeholder="Enter the max_length parameter (integer) if you are using SCRL or KiS", label="max_length", info="If you are using SCRL or KiS, fill in the parameter, if not, just ignore this.\n Hint: For SCRL, max_length should be shorter than the lenght of original prompt; For KiS, max_length should be longer than it.")
|
45 |
],
|
46 |
outputs=[
|
47 |
+
gr.Textbox(lines=1, info="Please wait patiently when proceeding it may take more than 2 minutes to generate since we are using CPUs for free."),
|
48 |
+
gr.Textbox(lines=1, info="With the compression ratio of: ")
|
49 |
]
|
50 |
)
|
51 |
|