Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,15 @@ summarizer = None
|
|
| 18 |
tokenizer = None
|
| 19 |
max_tokens = None
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Function to load the selected model
|
| 23 |
def load_model(model_name):
|
|
@@ -35,7 +44,6 @@ def load_model(model_name):
|
|
| 35 |
except Exception as e:
|
| 36 |
return f"Failed to load model {model_name}. Error: {str(e)}"
|
| 37 |
|
| 38 |
-
|
| 39 |
# Function to summarize the input text
|
| 40 |
def summarize_text(input, min_length, max_length):
|
| 41 |
if summarizer is None:
|
|
@@ -58,7 +66,6 @@ def summarize_text(input, min_length, max_length):
|
|
| 58 |
except Exception as e:
|
| 59 |
return f"Summarization failed: {str(e)}"
|
| 60 |
|
| 61 |
-
|
| 62 |
# Gradio Interface
|
| 63 |
with gr.Blocks() as demo:
|
| 64 |
with gr.Row():
|
|
@@ -70,7 +77,7 @@ with gr.Blocks() as demo:
|
|
| 70 |
min_length_slider = gr.Slider(minimum=0, maximum=100, step=1, label="Minimum Summary Length (%)", value=10)
|
| 71 |
max_length_slider = gr.Slider(minimum=0, maximum=100, step=1, label="Maximum Summary Length (%)", value=20)
|
| 72 |
|
| 73 |
-
input_text = gr.Textbox(label="Input text to summarize", lines=6)
|
| 74 |
summarize_button = gr.Button("Summarize Text")
|
| 75 |
output_text = gr.Textbox(label="Summarized text", lines=4)
|
| 76 |
|
|
|
|
| 18 |
tokenizer = None
|
| 19 |
max_tokens = None
|
| 20 |
|
| 21 |
+
# Example text for summarization
|
| 22 |
+
example_text = (
|
| 23 |
+
"Artificial intelligence (AI) is intelligence—perceiving, synthesizing, and inferring information—"
|
| 24 |
+
"demonstrated by machines, as opposed to intelligence displayed by non-human animals and humans. "
|
| 25 |
+
"Example tasks in which AI is employed include speech recognition, computer vision, language translation, "
|
| 26 |
+
"autonomous vehicles, and game playing. AI research has been defined as the field of study of intelligent "
|
| 27 |
+
"agents, which refers to any system that perceives its environment and takes actions that maximize its "
|
| 28 |
+
"chance of achieving its goals."
|
| 29 |
+
)
|
| 30 |
|
| 31 |
# Function to load the selected model
|
| 32 |
def load_model(model_name):
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
return f"Failed to load model {model_name}. Error: {str(e)}"
|
| 46 |
|
|
|
|
| 47 |
# Function to summarize the input text
|
| 48 |
def summarize_text(input, min_length, max_length):
|
| 49 |
if summarizer is None:
|
|
|
|
| 66 |
except Exception as e:
|
| 67 |
return f"Summarization failed: {str(e)}"
|
| 68 |
|
|
|
|
| 69 |
# Gradio Interface
|
| 70 |
with gr.Blocks() as demo:
|
| 71 |
with gr.Row():
|
|
|
|
| 77 |
min_length_slider = gr.Slider(minimum=0, maximum=100, step=1, label="Minimum Summary Length (%)", value=10)
|
| 78 |
max_length_slider = gr.Slider(minimum=0, maximum=100, step=1, label="Maximum Summary Length (%)", value=20)
|
| 79 |
|
| 80 |
+
input_text = gr.Textbox(label="Input text to summarize", lines=6, value=example_text)
|
| 81 |
summarize_button = gr.Button("Summarize Text")
|
| 82 |
output_text = gr.Textbox(label="Summarized text", lines=4)
|
| 83 |
|