Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -36,7 +36,7 @@ summarizer = pipeline(
|
|
36 |
"summarization",
|
37 |
model="sshleifer/distilbart-cnn-6-6"
|
38 |
)
|
39 |
-
|
40 |
def detect_objects(image):
|
41 |
yolo_model.to('cuda')
|
42 |
image_array = np.array(image) # Μετατροπή PIL → NumPy
|
@@ -48,7 +48,7 @@ def detect_objects(image):
|
|
48 |
label = yolo_model.names[class_id]
|
49 |
detected_objects.append(label)
|
50 |
return detected_objects
|
51 |
-
|
52 |
def generate_story(detected_objects):
|
53 |
story_prompt = f"Write a short story based on the following objects: {', '.join(detected_objects)}"
|
54 |
response = client.chat.completions.create(
|
@@ -57,12 +57,12 @@ def generate_story(detected_objects):
|
|
57 |
max_tokens=200
|
58 |
)
|
59 |
return response.choices[0].message.content.strip()
|
60 |
-
|
61 |
def summarize_story(story):
|
62 |
summary = summarizer(story, max_length=100, do_sample=False)[0]['summary_text']
|
63 |
scenes = sent_tokenize(summary)
|
64 |
return scenes
|
65 |
-
|
66 |
def generate_images(story):
|
67 |
scenes = summarize_story(story)
|
68 |
images = []
|
@@ -90,7 +90,7 @@ def generate_images(story):
|
|
90 |
continue
|
91 |
|
92 |
return images
|
93 |
-
|
94 |
def text_to_speech(story):
|
95 |
tts = gTTS(text=story, lang="en", slow=False)
|
96 |
audio_file_path = "story_audio.mp3"
|
|
|
36 |
"summarization",
|
37 |
model="sshleifer/distilbart-cnn-6-6"
|
38 |
)
|
39 |
+
|
40 |
def detect_objects(image):
|
41 |
yolo_model.to('cuda')
|
42 |
image_array = np.array(image) # Μετατροπή PIL → NumPy
|
|
|
48 |
label = yolo_model.names[class_id]
|
49 |
detected_objects.append(label)
|
50 |
return detected_objects
|
51 |
+
|
52 |
def generate_story(detected_objects):
|
53 |
story_prompt = f"Write a short story based on the following objects: {', '.join(detected_objects)}"
|
54 |
response = client.chat.completions.create(
|
|
|
57 |
max_tokens=200
|
58 |
)
|
59 |
return response.choices[0].message.content.strip()
|
60 |
+
|
61 |
def summarize_story(story):
|
62 |
summary = summarizer(story, max_length=100, do_sample=False)[0]['summary_text']
|
63 |
scenes = sent_tokenize(summary)
|
64 |
return scenes
|
65 |
+
|
66 |
def generate_images(story):
|
67 |
scenes = summarize_story(story)
|
68 |
images = []
|
|
|
90 |
continue
|
91 |
|
92 |
return images
|
93 |
+
|
94 |
def text_to_speech(story):
|
95 |
tts = gTTS(text=story, lang="en", slow=False)
|
96 |
audio_file_path = "story_audio.mp3"
|