hideosnes commited on
Commit
3d68164
·
verified ·
1 Parent(s): 8ef2c76

Update app.py

Browse files

Bug 1) prompt_map.get(lang_code, prompt_map["en"]) returns the dictionary for the language, while [style] accesses the specific prompt string for the chosen style.
Solution: Removed the unnecessary +[style] part since the style is already used to select the prompt

Bug 2) cleaned up UI

Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -66,7 +66,7 @@ def summarize(file, text, style, length):
66
  }#, <-- don't forget the comma!!!!!
67
  #"foo": { "precise": "another language or prompt map could go here"}
68
  }
69
- prompt = prompt_map.get(lang_code, prompt_map["en"])+[style] + " " + text_input
70
 
71
  # Summarization
72
  # Custom tokenizer: create a class with encode/decode methods following the HuggingFace
@@ -116,19 +116,26 @@ def summarize(file, text, style, length):
116
 
117
  return summary, ", ".join(keywords), original_len, summary_len, f"{reduction:.2f}%", fig
118
 
119
- with gr.Blocks() as app:
120
  gr.Markdown("Summarizer (T2T)")
121
- file = gr.File(label="Upload a PDF or a TXT file")
122
- text = gr.Textbox(label="Paste text from clipboard.", lines=10)
123
- style = gr.Dropdown(["Precise", "Sloppy", "Keywords"], label="Style")
124
- length = gr.Radio(["Short", "Middle", "Long"], label="Length")
125
- btn = gr.Button("Transform")
126
- summary = gr.Textbox(label="Summary")
127
- keywords = gr.Textbox(label="Important Keywords")
128
- original_len = gr.Number(label="Original Text Length")
129
- summary_len = gr.Number(label="Summary Length")
130
- reduction = gr.Textbox(label="Summary Efficiency")
131
- plot = gr.Plot(label="Summary Statistics")
 
 
 
 
 
 
 
132
 
133
  btn.click(
134
  summarize,
@@ -136,4 +143,4 @@ with gr.Blocks() as app:
136
  outputs=[summary, keywords, original_len, summary_len, reduction, plot]
137
  )
138
 
139
- app.launch()
 
66
  }#, <-- don't forget the comma!!!!!
67
  #"foo": { "precise": "another language or prompt map could go here"}
68
  }
69
+ prompt = prompt_map.get(lang_code, prompt_map["en"])[style] + " " + text_input
70
 
71
  # Summarization
72
  # Custom tokenizer: create a class with encode/decode methods following the HuggingFace
 
116
 
117
  return summary, ", ".join(keywords), original_len, summary_len, f"{reduction:.2f}%", fig
118
 
119
+ with gr.Blocks() as demo:
120
  gr.Markdown("Summarizer (T2T)")
121
+
122
+ with gr.Row(): #left column
123
+ with gr.Column():
124
+ file = gr.File(label="Upload a PDF or a TXT file")
125
+ text = gr.Textbox(label="Paste text from clipboard.", lines=10)
126
+
127
+ with gr.Row(): # for inline horizontal layout
128
+ style = gr.Dropdown(["Precise", "Sloppy", "Keywords"], label="Style")
129
+ length = gr.Radio(["Short", "Middle", "Long"], label="Length")
130
+ btn = gr.Button("Transform")
131
+
132
+ with gr.Column(): #right column
133
+ summary = gr.Textbox(label="Summary")
134
+ keywords = gr.Textbox(label="Important Keywords")
135
+ original_len = gr.Number(label="Original Text Length")
136
+ summary_len = gr.Number(label="Summary Length")
137
+ reduction = gr.Textbox(label="Summary Efficiency")
138
+ plot = gr.Plot(label="Summary Statistics")
139
 
140
  btn.click(
141
  summarize,
 
143
  outputs=[summary, keywords, original_len, summary_len, reduction, plot]
144
  )
145
 
146
+ demo.launch()