Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
@@ -1,12 +1,9 @@
|
|
1 |
from transformers import pipeline
|
2 |
|
3 |
-
#
|
4 |
pipe = pipeline("text2text-generation", 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,9 +12,6 @@ def split_text_into_chunks(text, chunk_size=1000):
|
|
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,9 +19,6 @@ def generate_lesson_from_chunks(chunks):
|
|
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
|
|
|
1 |
from transformers import pipeline
|
2 |
|
3 |
+
# Create the pipeline globally
|
4 |
pipe = pipeline("text2text-generation", model="google-t5/t5-base", device="cpu")
|
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 |
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 |
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
|