Bir tane excel dosyası var ve her satırında içerik var. Bu içerikler çok uzun ve ben bunları ya özetlemek ya da özgünleştirmek istiyorum.Python bilgim yok denilecek kadar. Aşağıdaki kodu çalıştırdım (Kod yapay zekaya yazdırıldı). Kod 20 satır istenileni yaptı diğerlerinde ya olduğu gibi bıraktı ya da eksik yaptı. Hatanın nerede olduğunu ya da kodun tamamını yazıp verebilecek var mı?
# -*- coding: utf-8 -*-
import pandas as pd
from groq import Groq
import time
# Groq API key (ücretsiz) - console.groq.com adresinden alın
GROQ_API_KEY = "BURAYA_API_KEY_YAPISTIRIN"
excel_file = r'C:\DOSYA YOLU\ozet.xlsx'
output_file = r'C:\DOSYA YOLU \ozet_sonuc.xlsx'
client = Groq(api_key=GROQ_API_KEY)
def groq_ozetle(text):
try:
chat = client.chat.completions.create(
messages=[{
"role": "user",
"content": f"""Bu Türkçe metni özetle:
KURALLAR:
- Maksimum 100 kelime
- Tam cümleler, nokta ile bitir
- Önemli tarihleri ve isimleri koru
- Yarım cümle ASLA yazma
Metin: {text}
Özet:"""
}],
model="llama-3.3-70b-versatile",
temperature=0.3,
max_tokens=300
)
ozet = chat.choices[0].message.content.strip()
if not ozet.endswith(('.', '!', '?')):
son = ozet.rfind('.')
ozet = ozet[:son+1] if son > 20 else ozet + '.'
return ozet
except Exception as e:
return text[:150] + "..."
df = pd.read_excel(excel_file)
for col in df.columns:
ozet_col = f"{col}_OZET"
df[ozet_col] = ""
for i, row in df.iterrows():
text = str(row[col])
if len(text.split()) >= 10:
print(f"Satir {i+1}...", end=" ")
df.at[i, ozet_col] = groq_ozetle(text)
df.to_excel(output_file, index=False)
print("OK")
time.sleep(0.5)
print(f"Bitti: {output_file}")