|
import gradio as gr |
|
from utils.ner_helpers import is_llm_model |
|
from typing import Dict, List, Any |
|
from tasks.summarization import text_summarization |
|
|
|
def summarization_ui(): |
|
"""Summarization UI component""" |
|
|
|
|
|
SUMMARY_MODELS = [ |
|
"gemini-2.0-flash" |
|
|
|
|
|
|
|
|
|
|
|
] |
|
DEFAULT_MODEL = "gemini-2.0-flash" |
|
|
|
def summarize(text, model, summary_length, custom_instructions): |
|
"""Process text for summarization""" |
|
if not text.strip(): |
|
return "No text provided" |
|
|
|
use_llm = is_llm_model(model) |
|
result = text_summarization( |
|
text=text, |
|
model=model, |
|
summary_length=summary_length, |
|
use_llm=use_llm |
|
) |
|
|
|
|
|
|
|
return result |
|
|
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
input_text = gr.Textbox( |
|
label="Input Text", |
|
lines=8, |
|
placeholder="Enter text to summarize...", |
|
elem_id="summary-input-text" |
|
) |
|
|
|
summary_length = gr.Radio( |
|
["Short", "Medium", "Long"], |
|
value="Medium", |
|
label="Summary Length", |
|
elem_id="summary-length-radio" |
|
) |
|
model = gr.Dropdown( |
|
SUMMARY_MODELS, |
|
value=DEFAULT_MODEL, |
|
label="Model", |
|
interactive=True, |
|
elem_id="summary-model-dropdown" |
|
) |
|
custom_instructions = gr.Textbox( |
|
label="Custom Instructions (optional)", |
|
lines=2, |
|
placeholder="Add any custom instructions for the model...", |
|
elem_id="summary-custom-instructions" |
|
) |
|
|
|
btn = gr.Button("Summarize", variant="primary", elem_id="summary-btn") |
|
|
|
with gr.Column(): |
|
output = gr.Textbox( |
|
label="Summary", |
|
lines=10, |
|
elem_id="summary-output" |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
btn.click( |
|
summarize, |
|
inputs=[input_text, model, summary_length, custom_instructions], |
|
outputs=output |
|
) |
|
|
|
return None |
|
|