Spaces:
Runtime error
Runtime error
Update app.py
Browse filesSiivottu koodia
app.py
CHANGED
|
@@ -76,7 +76,7 @@ data_collator = DataCollatorForSeq2Seq(tokenizer=tokenizer, model=model_name)
|
|
| 76 |
import torch
|
| 77 |
torch.cuda.empty_cache()
|
| 78 |
|
| 79 |
-
|
| 80 |
|
| 81 |
#pip install wandb
|
| 82 |
import os
|
|
@@ -107,7 +107,7 @@ for name, param in model.named_parameters():
|
|
| 107 |
training_args = Seq2SeqTrainingArguments(
|
| 108 |
output_dir='./results',
|
| 109 |
num_train_epochs=1,
|
| 110 |
-
per_device_train_batch_size=4,
|
| 111 |
per_device_eval_batch_size=4,
|
| 112 |
evaluation_strategy='epoch',
|
| 113 |
logging_dir='./logs',
|
|
@@ -122,7 +122,7 @@ trainer = Seq2SeqTrainer(
|
|
| 122 |
eval_dataset=tokenized_small_ds.shuffle().select(range(20, 100)), # Käytetään 200 esimerkkiä arvioimiseen
|
| 123 |
)
|
| 124 |
|
| 125 |
-
#
|
| 126 |
trainer.train()
|
| 127 |
|
| 128 |
#pip install rouge_score
|
|
@@ -170,7 +170,7 @@ new_model = MT5ForConditionalGeneration.from_pretrained(model_name)
|
|
| 170 |
from transformers import pipeline
|
| 171 |
import torch
|
| 172 |
|
| 173 |
-
|
| 174 |
# Restructured input
|
| 175 |
text = (
|
| 176 |
"Summarize the following information regarding psoriasis, its effects on skin health, and its potential health risks:\n\n"
|
|
@@ -186,10 +186,10 @@ text = (
|
|
| 186 |
# Määrittele laite (GPU tai CPU)
|
| 187 |
device = 0 if torch.cuda.is_available() else -1
|
| 188 |
|
| 189 |
-
#
|
| 190 |
summarizer = pipeline("summarization", model=new_model, tokenizer=new_tokenizer, device=device)
|
| 191 |
|
| 192 |
-
#
|
| 193 |
summary = summarizer(text,
|
| 194 |
max_length=120,
|
| 195 |
min_length=30,
|
|
@@ -213,8 +213,7 @@ cleaned_summary = re.sub(pattern, " ", summary).strip()
|
|
| 213 |
print(cleaned_summary)
|
| 214 |
|
| 215 |
|
| 216 |
-
|
| 217 |
-
#pip install gradio PyMuPDF
|
| 218 |
|
| 219 |
import gradio as gr
|
| 220 |
from transformers import T5Tokenizer, MT5ForConditionalGeneration
|
|
@@ -286,6 +285,6 @@ interface = gr.Interface(
|
|
| 286 |
description="Upload a PDF file to summarize its content."
|
| 287 |
)
|
| 288 |
|
| 289 |
-
|
| 290 |
# Launch the interface with debug mode enabled
|
| 291 |
interface.launch(debug=True)
|
|
|
|
| 76 |
import torch
|
| 77 |
torch.cuda.empty_cache()
|
| 78 |
|
| 79 |
+
|
| 80 |
|
| 81 |
#pip install wandb
|
| 82 |
import os
|
|
|
|
| 107 |
training_args = Seq2SeqTrainingArguments(
|
| 108 |
output_dir='./results',
|
| 109 |
num_train_epochs=1,
|
| 110 |
+
per_device_train_batch_size=4,
|
| 111 |
per_device_eval_batch_size=4,
|
| 112 |
evaluation_strategy='epoch',
|
| 113 |
logging_dir='./logs',
|
|
|
|
| 122 |
eval_dataset=tokenized_small_ds.shuffle().select(range(20, 100)), # Käytetään 200 esimerkkiä arvioimiseen
|
| 123 |
)
|
| 124 |
|
| 125 |
+
# train the model
|
| 126 |
trainer.train()
|
| 127 |
|
| 128 |
#pip install rouge_score
|
|
|
|
| 170 |
from transformers import pipeline
|
| 171 |
import torch
|
| 172 |
|
| 173 |
+
|
| 174 |
# Restructured input
|
| 175 |
text = (
|
| 176 |
"Summarize the following information regarding psoriasis, its effects on skin health, and its potential health risks:\n\n"
|
|
|
|
| 186 |
# Määrittele laite (GPU tai CPU)
|
| 187 |
device = 0 if torch.cuda.is_available() else -1
|
| 188 |
|
| 189 |
+
# Load the pipeline
|
| 190 |
summarizer = pipeline("summarization", model=new_model, tokenizer=new_tokenizer, device=device)
|
| 191 |
|
| 192 |
+
# Summarize the text
|
| 193 |
summary = summarizer(text,
|
| 194 |
max_length=120,
|
| 195 |
min_length=30,
|
|
|
|
| 213 |
print(cleaned_summary)
|
| 214 |
|
| 215 |
|
| 216 |
+
|
|
|
|
| 217 |
|
| 218 |
import gradio as gr
|
| 219 |
from transformers import T5Tokenizer, MT5ForConditionalGeneration
|
|
|
|
| 285 |
description="Upload a PDF file to summarize its content."
|
| 286 |
)
|
| 287 |
|
| 288 |
+
|
| 289 |
# Launch the interface with debug mode enabled
|
| 290 |
interface.launch(debug=True)
|