Fix
Browse files- app.py +11 -2
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -41,13 +41,22 @@ image_generator = StableDiffusionPipeline.from_pretrained(
|
|
| 41 |
lora_weights = "lacos03/std-1.5-lora-midjourney-1.0"
|
| 42 |
image_generator.load_lora_weights(lora_weights)
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# === Hàm xử lý ===
|
| 46 |
def summarize_article(article_text):
|
| 47 |
"""Tóm tắt bài viết và tạo prompt refinement"""
|
| 48 |
if not article_text.strip():
|
| 49 |
return "[Empty]", "[Empty]"
|
| 50 |
-
summary = summarizer(article_text,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
title = summary.split(".")[0] + "."
|
| 52 |
# Prompt refinement
|
| 53 |
input_ids = promptist_tokenizer(title.strip() + " Rephrase:", return_tensors="pt").input_ids.to(device)
|
|
|
|
| 41 |
lora_weights = "lacos03/std-1.5-lora-midjourney-1.0"
|
| 42 |
image_generator.load_lora_weights(lora_weights)
|
| 43 |
|
| 44 |
+
# Cấu hình beam search cho BART
|
| 45 |
+
NUM_BEAMS = 10
|
| 46 |
+
NO_REPEAT_NGRAM_SIZE = 3
|
| 47 |
+
LENGTH_PENALTY = 1.0
|
| 48 |
+
MIN_NEW_TOKENS = 10
|
| 49 |
+
MAX_NEW_TOKENS = 62
|
| 50 |
# === Hàm xử lý ===
|
| 51 |
def summarize_article(article_text):
|
| 52 |
"""Tóm tắt bài viết và tạo prompt refinement"""
|
| 53 |
if not article_text.strip():
|
| 54 |
return "[Empty]", "[Empty]"
|
| 55 |
+
summary = summarizer(article_text, num_beams=NUM_BEAMS,
|
| 56 |
+
no_repeat_ngram_size=NO_REPEAT_NGRAM_SIZE,
|
| 57 |
+
length_penalty=LENGTH_PENALTY,
|
| 58 |
+
min_new_tokens=MIN_NEW_TOKENS,
|
| 59 |
+
max_new_tokens=MAX_NEW_TOKENS, do_sample=False)[0]["summary_text"]
|
| 60 |
title = summary.split(".")[0] + "."
|
| 61 |
# Prompt refinement
|
| 62 |
input_ids = promptist_tokenizer(title.strip() + " Rephrase:", return_tensors="pt").input_ids.to(device)
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
gradio==3.50.2
|
| 2 |
transformers==4.42.4
|
| 3 |
-
torch==2.
|
| 4 |
diffusers==0.29.2
|
| 5 |
pillow==9.5.0
|
| 6 |
safetensors>=0.4.1
|
|
|
|
| 1 |
gradio==3.50.2
|
| 2 |
transformers==4.42.4
|
| 3 |
+
torch==2.4.1
|
| 4 |
diffusers==0.29.2
|
| 5 |
pillow==9.5.0
|
| 6 |
safetensors>=0.4.1
|