Spaces:
Runtime error

akhilsu commited on
Commit
cb91214
·
verified ·
1 Parent(s): 8f530ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -11,13 +11,13 @@ model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-1B-Instruct",
11
 
12
  def generate_summary(text: str, temperature: float, max_new_tokens: int) -> str:
13
  """
14
- Generate a summary from the input text using the llama3-8b model.
15
  Args:
16
  text (str): The input text to summarize.
17
  temperature (float): The temperature for generating the response.
18
  max_new_tokens (int): The maximum number of new tokens to generate.
19
  Returns:
20
- str: The generated summary.
21
  """
22
  input_ids = tokenizer.encode(text, return_tensors="pt").to(model.device)
23
 
@@ -29,17 +29,17 @@ def generate_summary(text: str, temperature: float, max_new_tokens: int) -> str:
29
  )
30
 
31
  summary = tokenizer.decode(output_ids[0], skip_special_tokens=True)
32
- return summary
33
 
34
  def summarize_file(file_path, temperature: float, max_new_tokens: int) -> str:
35
  """
36
- Summarize the content of an uploaded file.
37
  Args:
38
  file_path (str): The path of the uploaded file.
39
  temperature (float): The temperature for generating the response.
40
  max_new_tokens (int): The maximum number of new tokens to generate.
41
  Returns:
42
- str: The generated summary of the file's content.
43
  """
44
  # Read file content
45
  with open(file_path, 'r') as f:
@@ -60,7 +60,7 @@ with gr.Blocks() as demo:
60
  max_tokens = gr.Slider(minimum=50, maximum=512, step=1, value=150, label="Max New Tokens")
61
  submit_button = gr.Button("Generate Summary")
62
  with gr.Column():
63
- summary_output = gr.Textbox(lines=10, label="Summary", interactive=False)
64
 
65
  # Link button to generate summary from text input
66
  submit_button.click(
 
11
 
12
  def generate_summary(text: str, temperature: float, max_new_tokens: int) -> str:
13
  """
14
+ Generate a single-line summary from the input text using the llama3-8b model.
15
  Args:
16
  text (str): The input text to summarize.
17
  temperature (float): The temperature for generating the response.
18
  max_new_tokens (int): The maximum number of new tokens to generate.
19
  Returns:
20
+ str: The generated summary in a single line.
21
  """
22
  input_ids = tokenizer.encode(text, return_tensors="pt").to(model.device)
23
 
 
29
  )
30
 
31
  summary = tokenizer.decode(output_ids[0], skip_special_tokens=True)
32
+ return " ".join(summary.split())
33
 
34
  def summarize_file(file_path, temperature: float, max_new_tokens: int) -> str:
35
  """
36
+ Summarize the content of an uploaded file into a single line.
37
  Args:
38
  file_path (str): The path of the uploaded file.
39
  temperature (float): The temperature for generating the response.
40
  max_new_tokens (int): The maximum number of new tokens to generate.
41
  Returns:
42
+ str: The generated summary of the file's content in a single line.
43
  """
44
  # Read file content
45
  with open(file_path, 'r') as f:
 
60
  max_tokens = gr.Slider(minimum=50, maximum=512, step=1, value=150, label="Max New Tokens")
61
  submit_button = gr.Button("Generate Summary")
62
  with gr.Column():
63
+ summary_output = gr.Textbox(lines=1, label="Summary", interactive=False)
64
 
65
  # Link button to generate summary from text input
66
  submit_button.click(