diff --git a/src/async_request.py b/src/async_request.py index ba48716..31e6cca 100644 --- a/src/async_request.py +++ b/src/async_request.py @@ -9,7 +9,7 @@ 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" @@ -17,4 +17,4 @@ async def periodic_requests(url: str, data: Dict[str, Any], interval: int, count interval = 5 # Seconds between requests count = 10 # Number of requests -asyncio.run(periodic_requests(url, data, interval, count)) \ No newline at end of file +asyncio.run(periodic_requests(url, data, interval, count)) diff --git a/src/main.py b/src/main.py index df445d5..d06fca7 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,5 @@ import timeit -start = timeit.default_timer() +start = timeit.default_timer() # Execution time begins import json import os import scene_split @@ -9,20 +9,14 @@ 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}") @@ -30,18 +24,16 @@ def clear_story_folder(folder_path: str = "story") -> None: 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 \ No newline at end of file +import slideshow # Slideshow is played diff --git a/src/scene_split.py b/src/scene_split.py index 8ea4ead..bb61fe3 100644 --- a/src/scene_split.py +++ b/src/scene_split.py @@ -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) @@ -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)) \ No newline at end of file + print(main(story_text)) diff --git a/src/slideshow.py b/src/slideshow.py index c8c676d..0c82f16 100644 --- a/src/slideshow.py +++ b/src/slideshow.py @@ -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") @@ -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: @@ -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) diff --git a/src/text_to_img.py b/src/text_to_img.py index d6afb87..392d7ac 100644 --- a/src/text_to_img.py +++ b/src/text_to_img.py @@ -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", @@ -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") \ No newline at end of file + main("Cat eating burger", "burger-cat")