Spaces:
Runtime error
Runtime error
from transformers import pipeline | |
pipe = pipeline("text2text-generation", model="google-t5/t5-base", device="cpu") | |
pipe.model.config.pad_token_id = pipe.tokenizer.eos_token_id | |
def generate_lesson_from_transcript(doc_text): | |
try: | |
generated_text = pipe(doc_text, max_length=100, truncation=True)[0]['generated_text'] | |
output_path = "/tmp/generated_output.txt" | |
with open(output_path, "w") as file: | |
file.write(generated_text) | |
return generated_text, output_path | |
except Exception as e: | |
print(f"Bir hata oluştu: {str(e)}") | |
return "Bir hata oluştu", None | |
def split_text_into_chunks(text, chunk_size=1000): | |
words = text.split() | |
chunks = [] | |
for i in range(0, len(words), chunk_size): | |
chunk = ' '.join(words[i:i+chunk_size]) | |
chunks.append(chunk) | |
return chunks | |
def generate_lesson_from_chunks(chunks): | |
generated_texts = [] | |
for chunk in chunks: | |
generated_text = pipe(chunk, max_length=500)[0]['generated_text'] | |
generated_texts.append(generated_text) | |
return ' '.join(generated_texts) | |
def process_large_text(text): | |
chunks = split_text_into_chunks(text, chunk_size=1000) | |
generated_text = generate_lesson_from_chunks(chunks) | |
return generated_text |