Spaces:
Runtime error
Runtime error
Update text_analysis.py
Browse files- text_analysis.py +11 -13
text_analysis.py
CHANGED
@@ -1,15 +1,13 @@
|
|
1 |
-
# text_analysis.py
|
2 |
-
|
3 |
from transformers import pipeline
|
4 |
|
|
|
|
|
|
|
|
|
5 |
def generate_lesson_from_transcript(doc_text):
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
# pad_token_id ayarlama
|
10 |
-
pipe.model.config.pad_token_id = pipe.tokenizer.eos_token_id # veya uygun bir pad token değeri
|
11 |
-
|
12 |
-
# Ders anlatımı oluşturulacak metni üret
|
13 |
try:
|
14 |
generated_text = pipe(doc_text, max_length=100, truncation=True)[0]['generated_text']
|
15 |
output_path = "/tmp/generated_output.txt" # Web ortamında /tmp gibi geçici bir dizin kullanabilirsiniz
|
@@ -17,9 +15,9 @@ def generate_lesson_from_transcript(doc_text):
|
|
17 |
with open(output_path, "w") as file:
|
18 |
file.write(generated_text)
|
19 |
|
20 |
-
|
21 |
-
return generated_text, output_path # Burada hem metni hem de dosya yolunu döndürüyoruz
|
22 |
|
23 |
except Exception as e:
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
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("text-generation", model="jondurbin/airoboros-gpt-3.5-turbo-100k-7b", 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
|
|
|
15 |
with open(output_path, "w") as file:
|
16 |
file.write(generated_text)
|
17 |
|
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
|