Spaces:
Running
Running
Add: Claude-only restriction for table summaries
Browse files- summarizer.py +16 -10
summarizer.py
CHANGED
@@ -8,9 +8,22 @@ if not api_key or not api_key.strip():
|
|
8 |
raise RuntimeError("❌ OPENROUTER_API_KEY bulunamadı. Hugging Face Secrets kısmına eklenmeli.")
|
9 |
|
10 |
def build_prompt(text, mode, lang_mode="Otomatik", is_table=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
if is_table:
|
12 |
-
|
13 |
-
|
|
|
|
|
14 |
if "Karma" in mode:
|
15 |
instruction = """
|
16 |
Aşağıdaki metni 3 ayrı biçimde özetle:
|
@@ -30,15 +43,8 @@ Aşağıdaki metni 3 ayrı biçimde özetle:
|
|
30 |
else:
|
31 |
instruction = "Metni kısa ve teknik bir şekilde özetle."
|
32 |
|
33 |
-
|
34 |
-
if "Türkçeye" in lang_mode:
|
35 |
-
instruction += "\n\nSonuç Türkçeye çevrilsin."
|
36 |
-
elif "İngilizceye" in lang_mode:
|
37 |
-
instruction += "\n\nSonuç İngilizceye çevrilsin."
|
38 |
-
elif lang_mode == "Otomatik":
|
39 |
-
instruction += "\n\nMetnin dilini algıla ve uygun dilde özetle."
|
40 |
|
41 |
-
return f"{instruction}\n\nMetin:\n{text}"
|
42 |
|
43 |
def summarize_text(text, mode, model_name="anthropic/claude-3-haiku", lang_mode="Otomatik", is_table=False):
|
44 |
url = "https://openrouter.ai/api/v1/chat/completions"
|
|
|
8 |
raise RuntimeError("❌ OPENROUTER_API_KEY bulunamadı. Hugging Face Secrets kısmına eklenmeli.")
|
9 |
|
10 |
def build_prompt(text, mode, lang_mode="Otomatik", is_table=False):
|
11 |
+
# Önce çeviri/dil algılama talimatını hazırla
|
12 |
+
lang_instruction = ""
|
13 |
+
if "Çevir" in lang_mode:
|
14 |
+
if "Türkçeye" in lang_mode:
|
15 |
+
lang_instruction = "\n\nSonuç Türkçeye çevrilsin."
|
16 |
+
elif "İngilizceye" in lang_mode:
|
17 |
+
lang_instruction = "\n\nSonuç İngilizceye çevrilsin."
|
18 |
+
elif lang_mode == "Otomatik":
|
19 |
+
lang_instruction = "\n\nMetnin dilini algıla ve uygun dilde özetle."
|
20 |
+
|
21 |
+
# Eğer tablo varsa, özel prompt kullan
|
22 |
if is_table:
|
23 |
+
instruction = "Aşağıdaki tabloyu analiz et ve teknik bir şekilde özetle."
|
24 |
+
return f"{instruction}{lang_instruction}\n\n{text}"
|
25 |
+
|
26 |
+
# Diğer modlara göre yönlendir
|
27 |
if "Karma" in mode:
|
28 |
instruction = """
|
29 |
Aşağıdaki metni 3 ayrı biçimde özetle:
|
|
|
43 |
else:
|
44 |
instruction = "Metni kısa ve teknik bir şekilde özetle."
|
45 |
|
46 |
+
return f"{instruction}{lang_instruction}\n\nMetin:\n{text}"
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
|
|
48 |
|
49 |
def summarize_text(text, mode, model_name="anthropic/claude-3-haiku", lang_mode="Otomatik", is_table=False):
|
50 |
url = "https://openrouter.ai/api/v1/chat/completions"
|