|
import gradio as gr |
|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM |
|
|
|
|
|
models = { |
|
"Model 1 (lmsys/vicuna-13b-v1.3)": { |
|
"model_name": "lmsys/vicuna-13b-v1.3", |
|
"description": "Model 1: Foundation 13B Vicuna Model", |
|
}, |
|
"Model 2 (Aiyan99/theus_concepttagger)": { |
|
"model_name": "Aiyan99/theus_concepttagger", |
|
"description": "Model 2: My finetuned model", |
|
}, |
|
} |
|
|
|
|
|
def summarize_text(input_text, selected_model): |
|
|
|
model_info = models[selected_model] |
|
tokenizer = AutoTokenizer.from_pretrained(model_info["model_name"]) |
|
model = AutoModelForSeq2SeqLM.from_pretrained(model_info["model_name"]) |
|
|
|
|
|
input_ids = tokenizer.encode(input_text, return_tensors="pt", max_length=1024, truncation=True) |
|
summary_ids = model.generate(input_ids, max_length=10, min_length=1, length_penalty=1.0, num_beams=4, early_stopping=True) |
|
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True) |
|
return summary |
|
|
|
|
|
custom_theme = gr.theme( |
|
page_title="MLE - Project (Tuning and Infra Project)1MLE - Project (Tuning and Infra Project)", |
|
layout="wide", |
|
page_bgcolor="black", |
|
) |
|
|
|
iface = gr.Interface( |
|
fn=summarize_text, |
|
inputs=[gr.inputs.Textbox(label="Input Text"), gr.inputs.Radio(list(models.keys()), label="Select Model")], |
|
outputs="text", |
|
title="Text Summarization App", |
|
description="Choose a model for text summarization and enter the text to summarize.", |
|
theme=custom_theme, |
|
) |
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|