Arafath10 commited on
Commit
c34d173
1 Parent(s): 7cdd3ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -32
app.py CHANGED
@@ -53,25 +53,9 @@ def compress(original_prompt, compression_rate, base_model="xlm-roberta-large",
53
  return compressed_prompt, preserved_tokens, n_word_compressed
54
 
55
 
56
- title = "LLMLingua-2"
57
 
58
- header = """# LLMLingua-2: Efficient and Faithful Task-Agnostic Prompt Compression via Data Distillation
59
- _Zhuoshi Pan, Qianhui Wu, Huiqiang Jiang, Menglin Xia, Xufang Luo, Jue Zhang, Qingwei Lin, Victor Ruehle, Yuqing Yang, Chin-Yew Lin, H. Vicky Zhao, Lili Qiu, Dongmei Zhang_<br/>
60
- [[project page]](https://llmlingua.com/llmlingua2.html) [[paper]](https://arxiv.org/abs/2403.12968) [[code]](https://github.com/microsoft/LLMLingua)<br/>
61
- <br/>
62
- 💁‍♂️ This demo is deployed with HF "[CPU basic](https://huggingface.co/docs/hub/spaces-gpus)", the latency is expected to be longer.
63
- """
64
-
65
- theme = "soft"
66
- css = """#anno-img .mask {opacity: 0.5; transition: all 0.2s ease-in-out;}
67
- #anno-img .mask.active {opacity: 0.7}"""
68
-
69
- original_prompt_text = """John: So, um, I've been thinking about the project, you know, and I believe we need to, uh, make some changes. I mean, we want the project to succeed, right? So, like, I think we should consider maybe revising the timeline.
70
- Sarah: I totally agree, John. I mean, we have to be realistic, you know. The timeline is, like, too tight. You know what I mean? We should definitely extend it.
71
- """
72
-
73
- with gr.Blocks(title=title, css=css) as app:
74
- gr.Markdown(header)
75
  with gr.Row():
76
  with gr.Column(scale=3):
77
  original_prompt = gr.Textbox(value=original_prompt_text, label="Original Prompt", lines=10, max_lines=10, interactive=True)
@@ -88,6 +72,7 @@ with gr.Blocks(title=title, css=css) as app:
88
  n_word_original = gr.Textbox(lines=1, label="Original (GPT-4 Tokens)", interactive=False, value=len(tokenizer.encode(original_prompt_text)))
89
  n_word_compressed = gr.Textbox(lines=1, label="Compressed (GPT-4 Tokens)", interactive=False)
90
  button = gr.Button("⚡Click to Compress")
 
91
  with gr.Accordion(label="Compression Details", open=False):
92
  diff_text = gr.HighlightedText(label="Diff", combine_adjacent=False, show_legend=True, color_map={"+": "green"})
93
 
@@ -97,18 +82,5 @@ with gr.Blocks(title=title, css=css) as app:
97
  button.click(fn=compress,
98
  inputs=[original_prompt, compression_rate, base_model, force_tokens],
99
  outputs=[compressed_prompt, diff_text, n_word_compressed])
100
-
101
- qa_pairs = gr.DataFrame(label="GPT-4 generated QA pairs related to the original prompt:", headers=["Question", "Answer"], interactive=True,
102
- value=[["Summarize the conversation.","John suggests making changes to the project, specifically revising the timeline to ensure its success. Sarah agrees with John, acknowledging that the current timeline is too tight and supports the idea of extending it."]])
103
-
104
- gr.Markdown("## Examples (click to select)")
105
- dataset = gr.Dataset(label="MeetingBank",
106
- components=[gr.Textbox(visible=False, max_lines=3)],
107
- samples=original_prompt_list,
108
- type="index")
109
-
110
- dataset.select(fn=lambda idx: (examples[idx]["original_prompt"], examples[idx]["QA_pairs"]),
111
- inputs=[dataset],
112
- outputs=[original_prompt, qa_pairs])
113
-
114
  app.queue(max_size=10, api_open=False).launch(show_api=False)
 
53
  return compressed_prompt, preserved_tokens, n_word_compressed
54
 
55
 
56
+ title = "LLMLingua-2-cpu"
57
 
58
+ with gr.Blocks(title=title) as app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  with gr.Row():
60
  with gr.Column(scale=3):
61
  original_prompt = gr.Textbox(value=original_prompt_text, label="Original Prompt", lines=10, max_lines=10, interactive=True)
 
72
  n_word_original = gr.Textbox(lines=1, label="Original (GPT-4 Tokens)", interactive=False, value=len(tokenizer.encode(original_prompt_text)))
73
  n_word_compressed = gr.Textbox(lines=1, label="Compressed (GPT-4 Tokens)", interactive=False)
74
  button = gr.Button("⚡Click to Compress")
75
+
76
  with gr.Accordion(label="Compression Details", open=False):
77
  diff_text = gr.HighlightedText(label="Diff", combine_adjacent=False, show_legend=True, color_map={"+": "green"})
78
 
 
82
  button.click(fn=compress,
83
  inputs=[original_prompt, compression_rate, base_model, force_tokens],
84
  outputs=[compressed_prompt, diff_text, n_word_compressed])
85
+
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  app.queue(max_size=10, api_open=False).launch(show_api=False)