Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
pipe = pipeline("
|
| 5 |
|
| 6 |
def split_text_into_chunks(text, chunk_size=1000):
|
|
|
|
|
|
|
|
|
|
| 7 |
words = text.split()
|
| 8 |
chunks = []
|
| 9 |
for i in range(0, len(words), chunk_size):
|
|
@@ -12,6 +15,9 @@ def split_text_into_chunks(text, chunk_size=1000):
|
|
| 12 |
return chunks
|
| 13 |
|
| 14 |
def generate_lesson_from_chunks(chunks):
|
|
|
|
|
|
|
|
|
|
| 15 |
generated_texts = []
|
| 16 |
for chunk in chunks:
|
| 17 |
generated_text = pipe(chunk, max_length=500)[0]['generated_text']
|
|
@@ -19,6 +25,34 @@ def generate_lesson_from_chunks(chunks):
|
|
| 19 |
return ' '.join(generated_texts)
|
| 20 |
|
| 21 |
def process_large_text(text):
|
|
|
|
|
|
|
|
|
|
| 22 |
chunks = split_text_into_chunks(text, chunk_size=1000)
|
| 23 |
generated_text = generate_lesson_from_chunks(chunks)
|
| 24 |
-
return generated_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
+
# Pipeline'ı global olarak oluşturuyoruz
|
| 4 |
+
pipe = pipeline("translation", model="google-t5/t5-base", device="cpu")
|
| 5 |
|
| 6 |
def split_text_into_chunks(text, chunk_size=1000):
|
| 7 |
+
"""
|
| 8 |
+
Metni belirli sayıda kelimelik parçalara böler.
|
| 9 |
+
"""
|
| 10 |
words = text.split()
|
| 11 |
chunks = []
|
| 12 |
for i in range(0, len(words), chunk_size):
|
|
|
|
| 15 |
return chunks
|
| 16 |
|
| 17 |
def generate_lesson_from_chunks(chunks):
|
| 18 |
+
"""
|
| 19 |
+
Modeli her parça için çalıştırıp sonucu döndüren fonksiyon.
|
| 20 |
+
"""
|
| 21 |
generated_texts = []
|
| 22 |
for chunk in chunks:
|
| 23 |
generated_text = pipe(chunk, max_length=500)[0]['generated_text']
|
|
|
|
| 25 |
return ' '.join(generated_texts)
|
| 26 |
|
| 27 |
def process_large_text(text):
|
| 28 |
+
"""
|
| 29 |
+
Büyük metni işleyecek ve sonucu döndürecek fonksiyon.
|
| 30 |
+
"""
|
| 31 |
chunks = split_text_into_chunks(text, chunk_size=1000)
|
| 32 |
generated_text = generate_lesson_from_chunks(chunks)
|
| 33 |
+
return generated_text
|
| 34 |
+
|
| 35 |
+
text_analysis.py
|
| 36 |
+
from transformers import pipeline
|
| 37 |
+
|
| 38 |
+
# Modeli bir kez yükleyip her seferinde yeniden yüklememek için global değişken kullanabiliriz.
|
| 39 |
+
pipe = pipeline("translation", model="google-t5/t5-base", device="cpu")
|
| 40 |
+
pipe.model.config.pad_token_id = pipe.tokenizer.eos_token_id # pad_token_id ayarı
|
| 41 |
+
|
| 42 |
+
def generate_lesson_from_transcript(doc_text):
|
| 43 |
+
"""
|
| 44 |
+
Metin girişinden ders anlatımı üretir ve çıktı olarak metin ile dosya döndürür.
|
| 45 |
+
"""
|
| 46 |
+
try:
|
| 47 |
+
generated_text = pipe(doc_text, max_length=100, truncation=True)[0]['generated_text']
|
| 48 |
+
output_path = "/tmp/generated_output.txt" # Web ortamında /tmp gibi geçici bir dizin kullanabilirsiniz
|
| 49 |
+
|
| 50 |
+
with open(output_path, "w") as file:
|
| 51 |
+
file.write(generated_text)
|
| 52 |
+
|
| 53 |
+
return generated_text, output_path
|
| 54 |
+
|
| 55 |
+
except Exception as e:
|
| 56 |
+
# Hata mesajını daha ayrıntılı yazdırabiliriz.
|
| 57 |
+
print(f"Bir hata oluştu: {str(e)}")
|
| 58 |
+
return "Bir hata oluştu", None
|