Chan-Y commited on
Commit
b9c9dac
1 Parent(s): 8639815

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -8
app.py CHANGED
@@ -41,10 +41,10 @@ def summarize(file, n_words):
41
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=3000, chunk_overlap=200)
42
  chunks = text_splitter.create_documents([text])
43
  n_words = n_words
44
- template = ''' [INST]
45
  Your task is to summarize a long text into a concise summary of a specific number of words.
46
 
47
- The summary you generate must be EXACTLY {N_WORDS} words long.
48
 
49
  Before writing your final summary, first break down the key points of the text in a <scratchpad>. Identify the most important information that should be included in a summary of the specified length.
50
 
@@ -53,13 +53,10 @@ def summarize(file, n_words):
53
  Here is the long text to summarize:
54
  Text:
55
  {TEXT}
56
-
57
-
58
- [/INST]
59
  '''
60
  prompt = PromptTemplate(
61
  template=template,
62
- input_variables=['TEXT', "N_WORDS"]
63
  )
64
  formatted_prompt = prompt.format(TEXT=text, N_WORDS=n_words)
65
  output_summary = llm_engine_hf.invoke(formatted_prompt)
@@ -83,14 +80,13 @@ with gr.Blocks() as demo:
83
 
84
  with gr.Row():
85
  with gr.Column():
86
- n_words = gr.Slider(minimum=50, maximum=500, step=50, label="Number of words (approximately)")
87
  file = gr.File(label="Submit a file")
88
 
89
  with gr.Column():
90
  output_text = gr.Textbox(label="Summary", lines=20)
91
 
92
  submit_button = gr.Button("Summarize")
93
- submit_button.click(summarize, inputs=[file, n_words], outputs=output_text)
94
 
95
  def generate_file():
96
  summary_text = output_text
 
41
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=3000, chunk_overlap=200)
42
  chunks = text_splitter.create_documents([text])
43
  n_words = n_words
44
+ template = '''
45
  Your task is to summarize a long text into a concise summary of a specific number of words.
46
 
47
+ The summary you generate must be very detailed.
48
 
49
  Before writing your final summary, first break down the key points of the text in a <scratchpad>. Identify the most important information that should be included in a summary of the specified length.
50
 
 
53
  Here is the long text to summarize:
54
  Text:
55
  {TEXT}
 
 
 
56
  '''
57
  prompt = PromptTemplate(
58
  template=template,
59
+ input_variables=['TEXT']
60
  )
61
  formatted_prompt = prompt.format(TEXT=text, N_WORDS=n_words)
62
  output_summary = llm_engine_hf.invoke(formatted_prompt)
 
80
 
81
  with gr.Row():
82
  with gr.Column():
 
83
  file = gr.File(label="Submit a file")
84
 
85
  with gr.Column():
86
  output_text = gr.Textbox(label="Summary", lines=20)
87
 
88
  submit_button = gr.Button("Summarize")
89
+ submit_button.click(summarize, inputs=[file], outputs=output_text)
90
 
91
  def generate_file():
92
  summary_text = output_text