Mahmoud Amiri
commited on
Commit
·
2a83020
1
Parent(s):
6bf7c99
change the app
Browse files- app.py +71 -73
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,79 +1,77 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
"""
|
18 |
-
client = InferenceClient(
|
19 |
-
token=hf_token.token,
|
20 |
-
model="Bocklitz-Lab/lit2vec-tldr-bart-model"
|
21 |
-
)
|
22 |
-
|
23 |
-
# You can prepend the system message if needed
|
24 |
-
input_text = f"{system_message}\n\n{message}"
|
25 |
-
|
26 |
-
response = client.text_to_text(
|
27 |
-
input=input_text,
|
28 |
-
max_new_tokens=max_tokens,
|
29 |
-
temperature=temperature,
|
30 |
-
top_p=top_p
|
31 |
-
)
|
32 |
-
|
33 |
-
yield response
|
34 |
-
|
35 |
-
|
36 |
-
# Define the Gradio interface
|
37 |
-
chatbot = gr.ChatInterface(
|
38 |
-
fn=respond,
|
39 |
-
type="messages",
|
40 |
-
additional_inputs=[
|
41 |
-
gr.Textbox(
|
42 |
-
value="You are a friendly chatbot.",
|
43 |
-
label="System message",
|
44 |
-
lines=1
|
45 |
-
),
|
46 |
-
gr.Slider(
|
47 |
-
minimum=1,
|
48 |
-
maximum=2048,
|
49 |
-
value=512,
|
50 |
-
step=1,
|
51 |
-
label="Max new tokens"
|
52 |
-
),
|
53 |
-
gr.Slider(
|
54 |
-
minimum=0.1,
|
55 |
-
maximum=4.0,
|
56 |
-
value=0.7,
|
57 |
-
step=0.1,
|
58 |
-
label="Temperature"
|
59 |
-
),
|
60 |
-
gr.Slider(
|
61 |
-
minimum=0.1,
|
62 |
-
maximum=1.0,
|
63 |
-
value=0.95,
|
64 |
-
step=0.05,
|
65 |
-
label="Top-p (nucleus sampling)"
|
66 |
-
),
|
67 |
-
],
|
68 |
)
|
69 |
|
70 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
with gr.Blocks() as demo:
|
72 |
with gr.Row():
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
|
78 |
-
if __name__ == "__main__":
|
79 |
-
demo.launch()
|
|
|
1 |
+
import torch
|
2 |
import gradio as gr
|
3 |
+
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer, AutoConfig
|
4 |
+
|
5 |
+
# List of summarization models
|
6 |
+
model_names = [
|
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 |
+
# Example text for summarization
|
16 |
+
example_text = (
|
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 |
+
return f"Failed to load model {model_name}. Error: {str(e)}"
|
35 |
+
|
36 |
+
# Function to summarize the input text
|
37 |
+
def summarize_text(input, min_length, max_length):
|
38 |
+
if summarizer is None:
|
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:
|
56 |
+
return f"Summarization failed: {str(e)}"
|
57 |
+
|
58 |
+
# Gradio Interface
|
59 |
with gr.Blocks() as demo:
|
60 |
with gr.Row():
|
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)
|
68 |
+
|
69 |
+
input_text = gr.Textbox(label="Input text to summarize", lines=6, value=example_text)
|
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 |
|
77 |
+
demo.launch()
|
|
|
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
transformers
|
|
|
2 |
onnxruntime
|
3 |
gradio==4.19
|
4 |
huggingface_hub==0.22.2
|
|
|
1 |
transformers
|
2 |
+
torch
|
3 |
onnxruntime
|
4 |
gradio==4.19
|
5 |
huggingface_hub==0.22.2
|