Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,14 +12,18 @@ def smart_truncate(text, max_len):
|
|
12 |
return text[:text[:max_len+1].rfind(' ')].strip()
|
13 |
|
14 |
def generate_meta(description):
|
15 |
-
#
|
16 |
-
|
|
|
|
|
|
|
17 |
Create a title and description for product page.
|
18 |
Product name: Fenix ARB-L18-4000U
|
19 |
-
Description: {description
|
|
|
20 |
Output format:
|
21 |
-
{"title": "SEO заголовок до 60 символов", "description": "SEO описание до 160 символов"}
|
22 |
-
"""
|
23 |
|
24 |
inputs = tokenizer(prompt, return_tensors="pt", max_length=512, truncation=True)
|
25 |
|
@@ -50,7 +54,7 @@ Output format:
|
|
50 |
title = smart_truncate(f"Аккумулятор Fenix {clean_text}", 60)
|
51 |
desc = smart_truncate(clean_text, 160)
|
52 |
|
53 |
-
return title, desc
|
54 |
|
55 |
|
56 |
# Интерфейс
|
|
|
12 |
return text[:text[:max_len+1].rfind(' ')].strip()
|
13 |
|
14 |
def generate_meta(description):
|
15 |
+
# Очищаем входное описание
|
16 |
+
description = description.strip()
|
17 |
+
|
18 |
+
# Теперь безопасный f-string без .strip() внутри
|
19 |
+
prompt = """
|
20 |
Create a title and description for product page.
|
21 |
Product name: Fenix ARB-L18-4000U
|
22 |
+
Description: {description}
|
23 |
+
|
24 |
Output format:
|
25 |
+
{{"title": "SEO заголовок до 60 символов", "description": "SEO описание до 160 символов"}}
|
26 |
+
""".format(description=description)
|
27 |
|
28 |
inputs = tokenizer(prompt, return_tensors="pt", max_length=512, truncation=True)
|
29 |
|
|
|
54 |
title = smart_truncate(f"Аккумулятор Fenix {clean_text}", 60)
|
55 |
desc = smart_truncate(clean_text, 160)
|
56 |
|
57 |
+
return title, desc
|
58 |
|
59 |
|
60 |
# Интерфейс
|