Spaces:
Runtime error
Runtime error
Update text_analysis.py
Browse files- text_analysis.py +10 -6
text_analysis.py
CHANGED
|
@@ -1,13 +1,16 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
pipe = pipeline("
|
| 5 |
-
pipe.model.config.pad_token_id = pipe.tokenizer.eos_token_id #
|
| 6 |
|
| 7 |
def generate_lesson_from_transcript(doc_text):
|
|
|
|
|
|
|
|
|
|
| 8 |
try:
|
| 9 |
generated_text = pipe(doc_text, max_length=100, truncation=True)[0]['generated_text']
|
| 10 |
-
output_path = "/tmp/generated_output.txt" #
|
| 11 |
|
| 12 |
with open(output_path, "w") as file:
|
| 13 |
file.write(generated_text)
|
|
@@ -15,5 +18,6 @@ def generate_lesson_from_transcript(doc_text):
|
|
| 15 |
return generated_text, output_path
|
| 16 |
|
| 17 |
except Exception as e:
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
+
# Modeli bir kez yükleyip her seferinde yeniden yüklememek için global değişken kullanabiliriz.
|
| 4 |
+
pipe = pipeline("translation", model="google-t5/t5-base", device="cpu")
|
| 5 |
+
pipe.model.config.pad_token_id = pipe.tokenizer.eos_token_id # pad_token_id ayarı
|
| 6 |
|
| 7 |
def generate_lesson_from_transcript(doc_text):
|
| 8 |
+
"""
|
| 9 |
+
Metin girişinden ders anlatımı üretir ve çıktı olarak metin ile dosya döndürür.
|
| 10 |
+
"""
|
| 11 |
try:
|
| 12 |
generated_text = pipe(doc_text, max_length=100, truncation=True)[0]['generated_text']
|
| 13 |
+
output_path = "/tmp/generated_output.txt" # Web ortamında /tmp gibi geçici bir dizin kullanabilirsiniz
|
| 14 |
|
| 15 |
with open(output_path, "w") as file:
|
| 16 |
file.write(generated_text)
|
|
|
|
| 18 |
return generated_text, output_path
|
| 19 |
|
| 20 |
except Exception as e:
|
| 21 |
+
# Hata mesajını daha ayrıntılı yazdırabiliriz.
|
| 22 |
+
print(f"Bir hata oluştu: {str(e)}")
|
| 23 |
+
return "Bir hata oluştu", None
|