Mahmoud Amiri
commited on
Commit
·
8b34c5c
1
Parent(s):
fdde785
remove model selector
Browse files
app.py
CHANGED
@@ -2,36 +2,31 @@ import torch
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer, AutoConfig
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
"Bocklitz-Lab/lit2vec-tldr-bart-model"
|
8 |
-
]
|
9 |
|
10 |
# Placeholder for the summarizer pipeline, tokenizer, and maximum tokens
|
11 |
summarizer = None
|
12 |
tokenizer = None
|
13 |
max_tokens = None
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
"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."
|
18 |
-
)
|
19 |
-
|
20 |
-
# Function to load the selected model
|
21 |
-
def load_model(model_name):
|
22 |
global summarizer, tokenizer, max_tokens
|
23 |
try:
|
24 |
-
# Load the summarization pipeline with the selected model
|
25 |
summarizer = pipeline("summarization", model=model_name, torch_dtype=torch.float32)
|
26 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
27 |
config = AutoConfig.from_pretrained(model_name)
|
28 |
-
|
29 |
-
# Set a reasonable default for max_tokens if not available
|
30 |
max_tokens = getattr(config, 'max_position_embeddings', 1024)
|
31 |
-
|
32 |
-
return f"Model {model_name} loaded successfully! Max tokens: {max_tokens}"
|
33 |
except Exception as e:
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# Function to summarize the input text
|
37 |
def summarize_text(input, min_length, max_length):
|
@@ -39,17 +34,15 @@ def summarize_text(input, min_length, max_length):
|
|
39 |
return "No model loaded!"
|
40 |
|
41 |
try:
|
42 |
-
# Tokenize the input text and check the number of tokens
|
43 |
input_tokens = tokenizer.encode(input, return_tensors="pt")
|
44 |
num_tokens = input_tokens.shape[1]
|
|
|
45 |
if num_tokens > max_tokens:
|
46 |
return f"Error: Input exceeds the max token limit of {max_tokens}."
|
47 |
|
48 |
-
# Ensure min/max lengths are within bounds
|
49 |
min_summary_length = max(10, int(num_tokens * (min_length / 100)))
|
50 |
max_summary_length = min(max_tokens, int(num_tokens * (max_length / 100)))
|
51 |
|
52 |
-
# Summarize the input text
|
53 |
output = summarizer(input, min_length=min_summary_length, max_length=max_summary_length, truncation=True)
|
54 |
return output[0]['summary_text']
|
55 |
except Exception as e:
|
@@ -57,11 +50,7 @@ def summarize_text(input, min_length, max_length):
|
|
57 |
|
58 |
# Gradio Interface
|
59 |
with gr.Blocks() as demo:
|
60 |
-
|
61 |
-
model_dropdown = gr.Dropdown(choices=model_names, label="Choose a model", value="sshleifer/distilbart-cnn-12-6")
|
62 |
-
load_button = gr.Button("Load Model")
|
63 |
-
|
64 |
-
load_message = gr.Textbox(label="Load Status", interactive=False)
|
65 |
|
66 |
min_length_slider = gr.Slider(minimum=0, maximum=100, step=1, label="Minimum Summary Length (%)", value=10)
|
67 |
max_length_slider = gr.Slider(minimum=0, maximum=100, step=1, label="Maximum Summary Length (%)", value=20)
|
@@ -70,7 +59,6 @@ with gr.Blocks() as demo:
|
|
70 |
summarize_button = gr.Button("Summarize Text")
|
71 |
output_text = gr.Textbox(label="Summarized text", lines=4)
|
72 |
|
73 |
-
load_button.click(fn=load_model, inputs=model_dropdown, outputs=load_message)
|
74 |
summarize_button.click(fn=summarize_text, inputs=[input_text, min_length_slider, max_length_slider],
|
75 |
outputs=output_text)
|
76 |
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer, AutoConfig
|
4 |
|
5 |
+
# Model name
|
6 |
+
model_name = "Bocklitz-Lab/lit2vec-tldr-bart-model"
|
|
|
|
|
7 |
|
8 |
# Placeholder for the summarizer pipeline, tokenizer, and maximum tokens
|
9 |
summarizer = None
|
10 |
tokenizer = None
|
11 |
max_tokens = None
|
12 |
|
13 |
+
# Automatically load the model at startup
|
14 |
+
def initialize_model():
|
|
|
|
|
|
|
|
|
|
|
15 |
global summarizer, tokenizer, max_tokens
|
16 |
try:
|
|
|
17 |
summarizer = pipeline("summarization", model=model_name, torch_dtype=torch.float32)
|
18 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
19 |
config = AutoConfig.from_pretrained(model_name)
|
|
|
|
|
20 |
max_tokens = getattr(config, 'max_position_embeddings', 1024)
|
|
|
|
|
21 |
except Exception as e:
|
22 |
+
print(f"Model loading failed: {str(e)}")
|
23 |
+
|
24 |
+
initialize_model() # Load model at startup
|
25 |
+
|
26 |
+
# Example input
|
27 |
+
example_text = (
|
28 |
+
"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."
|
29 |
+
)
|
30 |
|
31 |
# Function to summarize the input text
|
32 |
def summarize_text(input, min_length, max_length):
|
|
|
34 |
return "No model loaded!"
|
35 |
|
36 |
try:
|
|
|
37 |
input_tokens = tokenizer.encode(input, return_tensors="pt")
|
38 |
num_tokens = input_tokens.shape[1]
|
39 |
+
|
40 |
if num_tokens > max_tokens:
|
41 |
return f"Error: Input exceeds the max token limit of {max_tokens}."
|
42 |
|
|
|
43 |
min_summary_length = max(10, int(num_tokens * (min_length / 100)))
|
44 |
max_summary_length = min(max_tokens, int(num_tokens * (max_length / 100)))
|
45 |
|
|
|
46 |
output = summarizer(input, min_length=min_summary_length, max_length=max_summary_length, truncation=True)
|
47 |
return output[0]['summary_text']
|
48 |
except Exception as e:
|
|
|
50 |
|
51 |
# Gradio Interface
|
52 |
with gr.Blocks() as demo:
|
53 |
+
gr.Markdown("## TL;DR Summarizer")
|
|
|
|
|
|
|
|
|
54 |
|
55 |
min_length_slider = gr.Slider(minimum=0, maximum=100, step=1, label="Minimum Summary Length (%)", value=10)
|
56 |
max_length_slider = gr.Slider(minimum=0, maximum=100, step=1, label="Maximum Summary Length (%)", value=20)
|
|
|
59 |
summarize_button = gr.Button("Summarize Text")
|
60 |
output_text = gr.Textbox(label="Summarized text", lines=4)
|
61 |
|
|
|
62 |
summarize_button.click(fn=summarize_text, inputs=[input_text, min_length_slider, max_length_slider],
|
63 |
outputs=output_text)
|
64 |
|