Spaces:
Build error
Build error
| import torch | |
| import gradio as gr | |
| #use a pipelines as a high-level helper | |
| from transformers import pipeline | |
| text_summary=pipeline(task="summarization",model="sshleifer/distilbart-cnn-12-6",torch_dtype=torch.bfloat16) | |
| """ | |
| text='''The First World War occurred from 1914 to 1918. In terms of human technological history, the scale of World War I was enabled by the technological advances of the Second Industrial Revolution and the resulting globalization that allowed global power projection and mass production of military hardware. It had been recognized that the complex system of opposing military alliances (the German and Austro-Hungarian Empires against the British, Italian, Russian, and French Empires) was likely, if war broke out, to lead to a worldwide conflict. That caused a very minute conflict between two countries to have the potential to set off a domino effect of alliances, triggering a world war. The fact that the powers involved had large overseas empires virtually guaranteed that such a war would be worldwide, as the colonies' resources would be a crucial strategic factor. The same strategic considerations also ensured that the combatants would strike at each other's colonies, thus spreading the wars far more widely than those of pre-Columbian times. | |
| War crimes were perpetrated in World War I. Chemical weapons were used in the war despite the Hague Conventions of 1899 and 1907 having outlawed the use of such weapons in warfare. The Ottoman Empire was responsible for the Armenian genocide, during the First World War, as well as other war crimes. | |
| """ | |
| #print(text_summary(text)) | |
| #User interface | |
| """ | |
| def summary(input): | |
| output=text_summary(input) | |
| return output[0]['summary_text'] | |
| gr.close_all() | |
| demo=gr.Interface(fn=summary,inputs="text",outputs="text") | |
| demo.launch() | |
| """ | |
| import gradio as gr | |
| import time | |
| def text_summary(text): | |
| # Dummy function for testing; replace with your real summarizer | |
| return [{"summary_text": text[:100] + "..."}] | |
| def summary(text): | |
| time.sleep(2) # simulate processing delay | |
| output = text_summary(text) | |
| return output[0]['summary_text'] | |
| def on_submit(text): | |
| if not text.strip(): | |
| return "", gr.update(value="", visible=False), "" | |
| start = time.time() | |
| # processing message | |
| proc_msg = f"processing | 0.0s" | |
| result = summary(text) | |
| elapsed = time.time() - start | |
| proc_msg = f"processing | {elapsed:.1f}s" | |
| return result, gr.update(value=proc_msg, visible=True), text | |
| def clear_all(): | |
| return "", gr.update(value="", visible=False), "" | |
| def flag_action(_): | |
| return "Flagged!", gr.update(visible=False), "" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("### Project 1: Text Summarizer") | |
| gr.Markdown("THIS APPLICATION WILL BE USED TO SUMMARIZE THE TEXT") | |
| with gr.Row(): | |
| with gr.Column(scale=2): | |
| input_text = gr.Textbox(label="Input text to summarize", lines=10, placeholder="Enter text here...") | |
| with gr.Row(): | |
| clear_btn = gr.Button("Clear") | |
| submit_btn = gr.Button("Submit", variant="primary") | |
| with gr.Column(scale=2): | |
| output_text = gr.Textbox(label="Output summary", lines=10, interactive=False) | |
| processing_label = gr.Label(value="", visible=False) | |
| flag_btn = gr.Button("Flag") | |
| submit_btn.click(on_submit, inputs=input_text, outputs=[output_text, processing_label, input_text]) | |
| clear_btn.click(clear_all, inputs=None, outputs=[input_text, processing_label, input_text]) | |
| flag_btn.click(flag_action, inputs=input_text, outputs=[output_text, processing_label, input_text]) | |
| demo.launch() | |