Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,24 +31,50 @@ def generate_summary(text: str, temperature: float, max_new_tokens: int) -> str:
|
|
| 31 |
summary = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 32 |
return summary
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# Gradio block for text summarization
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
gr.Markdown("<h1>Text Summarization Application</h1>")
|
| 37 |
with gr.Row():
|
| 38 |
with gr.Column():
|
| 39 |
text_input = gr.Textbox(lines=10, label="Input Text")
|
|
|
|
| 40 |
temperature = gr.Slider(minimum=0, maximum=1, step=0.1, value=0.7, label="Temperature")
|
| 41 |
max_tokens = gr.Slider(minimum=50, maximum=512, step=1, value=150, label="Max New Tokens")
|
| 42 |
submit_button = gr.Button("Generate Summary")
|
| 43 |
with gr.Column():
|
| 44 |
summary_output = gr.Textbox(lines=10, label="Summary", interactive=False)
|
| 45 |
|
|
|
|
| 46 |
submit_button.click(
|
| 47 |
fn=generate_summary,
|
| 48 |
inputs=[text_input, temperature, max_tokens],
|
| 49 |
outputs=summary_output
|
| 50 |
)
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
if __name__ == "__main__":
|
| 53 |
demo.launch()
|
| 54 |
-
|
|
|
|
| 31 |
summary = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 32 |
return summary
|
| 33 |
|
| 34 |
+
def summarize_file(file, temperature: float, max_new_tokens: int) -> str:
|
| 35 |
+
"""
|
| 36 |
+
Summarize the content of an uploaded file.
|
| 37 |
+
Args:
|
| 38 |
+
file: The uploaded file object.
|
| 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.name, 'r') as f:
|
| 46 |
+
text = f.read()
|
| 47 |
+
|
| 48 |
+
# Generate summary
|
| 49 |
+
summary = generate_summary(text, temperature, max_new_tokens)
|
| 50 |
+
return summary
|
| 51 |
+
|
| 52 |
# Gradio block for text summarization
|
| 53 |
with gr.Blocks() as demo:
|
| 54 |
gr.Markdown("<h1>Text Summarization Application</h1>")
|
| 55 |
with gr.Row():
|
| 56 |
with gr.Column():
|
| 57 |
text_input = gr.Textbox(lines=10, label="Input Text")
|
| 58 |
+
file_input = gr.File(label="Upload Text File", file_count="single", type="file")
|
| 59 |
temperature = gr.Slider(minimum=0, maximum=1, step=0.1, value=0.7, label="Temperature")
|
| 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(
|
| 67 |
fn=generate_summary,
|
| 68 |
inputs=[text_input, temperature, max_tokens],
|
| 69 |
outputs=summary_output
|
| 70 |
)
|
| 71 |
|
| 72 |
+
# Link file upload to summary generation
|
| 73 |
+
file_input.change(
|
| 74 |
+
fn=summarize_file,
|
| 75 |
+
inputs=[file_input, temperature, max_tokens],
|
| 76 |
+
outputs=summary_output
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
if __name__ == "__main__":
|
| 80 |
demo.launch()
|
|
|