Spaces:
Runtime error
Runtime error
Update text_analysis.py
Browse files- text_analysis.py +10 -8
text_analysis.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
-
# Pipeline ile metin üretim fonksiyonu
|
| 4 |
def generate_lesson_from_transcript(doc_text):
|
| 5 |
# Text generation pipeline'ını başlatıyoruz
|
| 6 |
pipe = pipeline("text-generation", model="jondurbin/airoboros-gpt-3.5-turbo-100k-7b", device="cpu")
|
|
@@ -10,14 +11,15 @@ def generate_lesson_from_transcript(doc_text):
|
|
| 10 |
|
| 11 |
# Ders anlatımı oluşturulacak metni üret
|
| 12 |
try:
|
| 13 |
-
generated_text = pipe(doc_text, max_length=
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
with open("generated_output.txt", "w") as file:
|
| 17 |
file.write(generated_text)
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
except Exception as e:
|
| 20 |
print(f"Bir hata oluştu: {e}")
|
| 21 |
-
return None # Hata durumunda
|
| 22 |
-
|
| 23 |
-
return generated_text # Üretilen metni geri döndürüyoruz
|
|
|
|
| 1 |
+
# text_analysis.py
|
| 2 |
+
|
| 3 |
from transformers import pipeline
|
| 4 |
|
|
|
|
| 5 |
def generate_lesson_from_transcript(doc_text):
|
| 6 |
# Text generation pipeline'ını başlatıyoruz
|
| 7 |
pipe = pipeline("text-generation", model="jondurbin/airoboros-gpt-3.5-turbo-100k-7b", device="cpu")
|
|
|
|
| 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
|
| 16 |
|
| 17 |
+
with open(output_path, "w") as file:
|
|
|
|
| 18 |
file.write(generated_text)
|
| 19 |
+
|
| 20 |
+
# Dosyayı Gradio ile kullanıcıya sunmak
|
| 21 |
+
return generated_text, output_path # Burada hem metni hem de dosya yolunu döndürüyoruz
|
| 22 |
+
|
| 23 |
except Exception as e:
|
| 24 |
print(f"Bir hata oluştu: {e}")
|
| 25 |
+
return "Bir hata oluştu", None # Hata durumunda geri dönen mesaj
|
|
|
|
|
|