File size: 3,938 Bytes
2a83020
ed16dde
2a83020
 
8b34c5c
 
2a83020
 
 
 
 
 
8b34c5c
 
2a83020
 
 
 
 
 
 
8b34c5c
 
 
 
 
 
 
 
2a83020
 
 
 
 
 
 
 
 
8b34c5c
2a83020
 
 
 
 
 
 
 
 
 
 
 
dc732ec
8b34c5c
2a83020
 
 
 
 
 
 
 
 
 
ed16dde
2a83020
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import torch
import gradio as gr
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer, AutoConfig

# Model name
model_name = "Bocklitz-Lab/lit2vec-tldr-bart-model"

# Placeholder for the summarizer pipeline, tokenizer, and maximum tokens
summarizer = None
tokenizer = None
max_tokens = None

# Automatically load the model at startup
def initialize_model():
    global summarizer, tokenizer, max_tokens
    try:
        summarizer = pipeline("summarization", model=model_name, torch_dtype=torch.float32)
        tokenizer = AutoTokenizer.from_pretrained(model_name)
        config = AutoConfig.from_pretrained(model_name)
        max_tokens = getattr(config, 'max_position_embeddings', 1024)
    except Exception as e:
        print(f"Model loading failed: {str(e)}")

initialize_model()  # Load model at startup

# Example input
example_text = (
    "Ultraviolet B (UVB; 290~320nm) irradiation-induced lipid peroxidation induces inflammatory responses that lead to skin wrinkle formation and epidermal thickening. Peroxisome proliferator-activated receptor (PPAR) α/γ dual agonists have the potential to be used as anti-wrinkle agents because they inhibit inflammatory response and lipid peroxidation. In this study, we evaluated the function of 2-bromo-4-(5-chloro-benzo[d]thiazol-2-yl) phenol (MHY 966), a novel synthetic PPAR α/γ dual agonist, and investigated its anti-inflammatory and anti-lipid peroxidation effects. The action of MHY 966 as a PPAR α/γ dual agonist was also determined in vitro by reporter gene assay. Additionally, 8-week-old melanin-possessing hairless mice 2 (HRM2) were exposed to 150 mJ/cm2 UVB every other day for 17 days and MHY 966 was simultaneously pre-treated every day for 17 days to investigate the molecular mechanisms involved. MHY 966 was found to stimulate the transcriptional activities of both PPAR α and γ. In HRM2 mice, we found that the skins of mice exposed to UVB showed significantly increased pro-inflammatory mediator levels (NF-κB, iNOS, and COX-2) and increased lipid peroxidation, whereas MHY 966 co-treatment down-regulated these effects of UVB by activating PPAR α and γ. Thus, the present study shows that MHY 966 exhibits beneficial effects on inflammatory responses and lipid peroxidation by simultaneously activating PPAR α and γ. The major finding of this study is that MHY 966 demonstrates potential as an agent against wrinkle formation associated with chronic UVB exposure."
)

# Function to summarize the input text
def summarize_text(input, min_length, max_length):
    if summarizer is None:
        return "No model loaded!"

    try:
        input_tokens = tokenizer.encode(input, return_tensors="pt")
        num_tokens = input_tokens.shape[1]

        if num_tokens > max_tokens:
            return f"Error: Input exceeds the max token limit of {max_tokens}."

        min_summary_length = max(10, int(num_tokens * (min_length / 100)))
        max_summary_length = min(max_tokens, int(num_tokens * (max_length / 100)))

        output = summarizer(input, min_length=min_summary_length, max_length=max_summary_length, truncation=True)
        return output[0]['summary_text']
    except Exception as e:
        return f"Summarization failed: {str(e)}"

# Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("## TL;DR Summarizer")

    min_length_slider = gr.Slider(minimum=0, maximum=100, step=1, label="Minimum Summary Length (%)", value=10)
    max_length_slider = gr.Slider(minimum=0, maximum=100, step=1, label="Maximum Summary Length (%)", value=20)

    input_text = gr.Textbox(label="Input text to summarize", lines=6, value=example_text)
    summarize_button = gr.Button("Summarize Text")
    output_text = gr.Textbox(label="Summarized text", lines=4)

    summarize_button.click(fn=summarize_text, inputs=[input_text, min_length_slider, max_length_slider],
                           outputs=output_text)

demo.launch()