Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/async_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ async def send_request(session: aiohttp.ClientSession, url: str, data: Dict[str,
async def periodic_requests(url: str, data: Dict[str, Any], interval: int, count: int) -> None:
async with aiohttp.ClientSession() as session:
for _ in range(count):
asyncio.create_task(send_request(session, url, data)) # Fire and forget
asyncio.create_task(send_request(session, url, data))
await asyncio.sleep(interval) # Wait before sending the next request

url = "https://api.example.com/endpoint"
data = {"key": "value"}
interval = 5 # Seconds between requests
count = 10 # Number of requests

asyncio.run(periodic_requests(url, data, interval, count))
asyncio.run(periodic_requests(url, data, interval, count))
26 changes: 9 additions & 17 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import timeit
start = timeit.default_timer()
start = timeit.default_timer() # Execution time begins
import json
import os
import scene_split
Expand All @@ -9,39 +9,31 @@
with open("story.txt", "r", encoding="utf-8") as f:
story = f.read()

def clear_story_folder(folder_path: str = "story") -> None:
def clear_story_folder(folder_path: str = "story") -> None: # Folder path generation (if not exists)
if os.path.exists(folder_path):
shutil.rmtree(folder_path)
os.makedirs(folder_path)

clear_story_folder()
scenes = scene_split.main(story,0.7)
clear_story_folder() # Messages for splitted scenes and quantity
scenes = scene_split.main(story, 0.7)
print("Scenes splitted successfully!")
# print(scenes)
# for i in scenes:
# print(i[0])

# Scenes to prompt
# print(scenes)
number_of_scenes = len(scenes)
print(f"Number of scenes: {number_of_scenes}")

print("\n")
image_type = input("Enter the type of image you want to generate (realistic, cartoon, abstract): ")
print("\n")

for i, scene in enumerate(scenes, 1):
for i, scene in enumerate(scenes, 1): # Scenes to prompt
prompt = f"Make a {image_type} image of" + scene
# print(prompt)
text_to_img.main(prompt, f"story/image-{i}")

# Folder and File name generation
story_dict = {f"story/image-{i}.png": line for i, line in enumerate(scenes, 1)}
story_dict = {f"story/image-{i}.png": line for i, line in enumerate(scenes, 1)} # Folder and file name generation

with open("story.json", "w") as f:
json.dump(story_dict, f, indent=4)

end = timeit.default_timer()
print(f"Time taken: {end-start} seconds")
end = timeit.default_timer() # Execution time ends
print(f"Time taken: {end-start} seconds") # Total execution time

import slideshow
import slideshow # Slideshow is played
13 changes: 10 additions & 3 deletions src/scene_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
import re
from typing import List

story_text: str = """John walked into the forest. He heard rustling behind him. The trees loomed tall as he pressed forward, his heart pounding. Later that night, he found a small cabin. It looked abandoned, but the door creaked open when he pushed it. The wind howled outside as he stepped in. Inside the cabin, an old man sat by the fire. He wore a long cloak and stared at John as if expecting him. In the morning, John woke up to find the man missing. The fire had gone cold. He stepped outside and saw footprints leading into the misty woods. With no other choice, he followed the footprints. The deeper he went, the more uneasy he felt, as if someone—or something—was watching him."""
story_text: str = '''John walked into the forest. He heard rustling behind him.
The trees loomed tall as he pressed forward, his heart pounding. Later that
night, he found a small cabin. It looked abandoned, but the door creaked open
when he pushed it. The wind howled outside as he stepped in. Inside the cabin,
an old man sat by the fire. He wore a long cloak and stared at John as if
expecting him. In the morning, John woke up to find the man missing. The fire
had gone cold. He stepped outside and saw footprints leading into the misty
woods. With no other choice, he followed the footprints. The deeper he went,
the more uneasy he felt, as if someone—or something—was watching him.''' # Example story text following multiline best practices in Python

def split_into_sentences(text: str) -> List[str]:
return re.findall(r"[^.!?]+", text)
Expand Down Expand Up @@ -43,8 +51,7 @@ def main(story_text: str, threshold: float = 0.5) -> List[str]:
i += 1

merged_sentences.append(sentences[-1])
# print("Similarity array:", similarity_array)
return merged_sentences

if __name__ == "__main__":
print(main(story_text))
print(main(story_text))
5 changes: 2 additions & 3 deletions src/slideshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
image_texts = json.load(file)

image_paths: List[str] = list(image_texts.keys())
# print(image_texts)

root = tk.Tk()
root.title("Image Slideshow with Text")
Expand Down Expand Up @@ -40,7 +39,7 @@ def update_image() -> None:
idx = (idx + 1) % len(image_texts)
root.after(5000, update_image)

def toggle_pause() -> None:
def toggle_pause() -> None: # Commands for controlling the images
global paused
paused = not paused
if not paused:
Expand All @@ -56,7 +55,7 @@ def prev_image() -> None:
idx = (idx - 1) % len(image_texts)
update_image()

btn_frame = tk.Frame(root)
btn_frame = tk.Frame(root) # Buttons for controlling the images through commands
btn_frame.pack()

btn_prev = tk.Button(btn_frame, text="<< Previous", command=prev_image)
Expand Down
8 changes: 2 additions & 6 deletions src/text_to_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import time
import os
from dotenv import load_dotenv
from PIL import Image

load_dotenv()

TOGETHER_API_KEY = os.getenv("TOGETHER_AI_API_KEY")
client = Together(api_key=TOGETHER_API_KEY)

def main(myprompt: str, img_file_name: str):
def main(myprompt: str, img_file_name: str): # Images main format
response = client.images.generate(
prompt=myprompt,
model="black-forest-labs/FLUX.1-schnell-Free",
Expand All @@ -20,14 +19,11 @@ def main(myprompt: str, img_file_name: str):
n=1,
response_format="b64_json",
)
# print(response.data[0].b64_json)
imgstring: str = response.data[0].b64_json
imgdata: bytes = base64.b64decode(imgstring)
filename: str = f'{img_file_name}.png'
with open(filename, 'wb') as f:
f.write(imgdata)
# image = Image.open(filename)
# image.show()

if __name__=="__main__":
main("Cat eating burger", "burger-cat")
main("Cat eating burger", "burger-cat")