Skip to content

Commit bfada9b

Browse files
committed
Updates and fixes
1 parent 8e78f22 commit bfada9b

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

‎logs/logs.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
Running on local URL: http://127.0.0.1:7860
22

33
To create a public link, set `share=True` in `launch()`.
4+
action: create_image_with_fal -> {'name': 'create_image_with_fal', 'group': 'fal_actions', 'pointer': <function create_image_with_fal at 0x0000020270B72DD0>, 'agent_action': {'type': 'function', 'function': {'name': 'create_image_with_fal', 'description': '\n Generates an image using the FAL model service and downloads it to a local directory.\n\n Args:\n prompt (str): The text prompt to generate the image.\n model (str, optional): The FAL model identifier to use for image generation. Default is "fal-ai/flux-pro".\n image_size (str, optional): The desired image size. Default is "landscape_4_3".\n num_inference_steps (int, optional): The number of inference steps for image generation. Default is 28.\n guidance_scale (float, optional): The guidance scale for image generation. Default is 3.5.\n seed: The seed used to as the randomized input into the model\n\n Returns:\n str: The local filename of the downloaded image if successful.\n\n ', 'parameters': {'type': 'object', 'properties': {'prompt': {'type': 'string', 'description': 'prompt'}, 'model': {'type': 'string', 'description': 'model'}, 'image_size': {'type': 'string', 'description': 'image_size'}, 'num_inference_steps': {'type': 'string', 'description': 'num_inference_steps'}, 'guidance_scale': {'type': 'string', 'description': 'guidance_scale'}, 'seed': {'type': 'string', 'description': 'seed'}}, 'required': ['prompt']}}}, 'prompt_template': None}
5+
action: create_image_with_fal -> {'prompt': 'A fantastical scene featuring a majestic castle with towers reaching up to the clouds. The castle is surrounded by a wide moat filled with strange, otherworldly creatures. A drawbridge spans the moat, leading to the open castle gates. Various peasants, farmers, merchants, and knights are walking through the gates and on the drawbridge, going about their daily activities. The scene is captured in a wide, low-angle shot with a cinematic camera, emphasizing the grandeur and scale of the castle and its surroundings.', 'num_inference_steps': '28', 'guidance_scale': '20.0', 'seed': '42'}
6+
https://v2.fal.media/files/01bcaa1c469c4ce388e804a7d65eb88b_e8fdda34d60c49a08d52e459e437f09e.jpg
7+
action: create_image_with_fal(args={"prompt": "A fantastical scene featuring a majestic castle with towers reaching up to the clouds. The castle is surrounded by a wide moat filled with strange, otherworldly creatures. A drawbridge spans the moat, leading to the open castle gates. Various peasants, farmers, merchants, and knights are walking through the gates and on the drawbridge, going about their daily activities. The scene is captured in a wide, low-angle shot with a cinematic camera, emphasizing the grandeur and scale of the castle and its surroundings.", "num_inference_steps": "28", "guidance_scale": "20.0", "seed": "42"}) -> A_fantastical_scene__fal-ai_flux-pro_20.0_28_304f0252.png
8+
action: create_image -> {'name': 'create_image', 'group': 'image_actions', 'pointer': <function create_image at 0x0000020270C6BD00>, 'agent_action': {'type': 'function', 'function': {'name': 'create_image', 'description': '\n Generate an image based on the provided prompt using the DALL-E model.\n Args:\n prompt (str): The prompt used to generate the image.\n model (str, optional): The model used to generate the image. Defaults to "dall-e-3".\n size (str, optional): The size of the image in pixels. Defaults to "1024x1024". Options are 1024x1024, 1024x1792 or 1792x1024.\n quality (str, optional): The quality of the generation. Defaults to "standard". Options are "standard" or "hd" for high definition.\n n (int, optional): The number of generations. Defaults to 1. Always 1 for now.\n Returns:\n str: The path to the generated image file.\n ', 'parameters': {'type': 'object', 'properties': {'prompt': {'type': 'string', 'description': 'prompt'}, 'model': {'type': 'string', 'description': 'model'}, 'size': {'type': 'string', 'description': 'size'}, 'quality': {'type': 'string', 'description': 'quality'}, 'n': {'type': 'string', 'description': 'n'}}, 'required': ['prompt']}}}, 'prompt_template': None}
9+
action: create_image -> {'prompt': 'A fantastical scene featuring a majestic castle with towers reaching up to the clouds. The castle is surrounded by a wide moat filled with strange, otherworldly creatures. A drawbridge spans the moat, leading to the open castle gates. Various peasants, farmers, merchants, and knights are walking through the gates and on the drawbridge, going about their daily activities. The scene is captured in a wide, low-angle shot with a cinematic camera, emphasizing the grandeur and scale of the castle and its surroundings.', 'size': '1024x1024'}
10+
action: create_image(args={"prompt": "A fantastical scene featuring a majestic castle with towers reaching up to the clouds. The castle is surrounded by a wide moat filled with strange, otherworldly creatures. A drawbridge spans the moat, leading to the open castle gates. Various peasants, farmers, merchants, and knights are walking through the gates and on the drawbridge, going about their daily activities. The scene is captured in a wide, low-angle shot with a cinematic camera, emphasizing the grandeur and scale of the castle and its surroundings.", "size": "1024x1024"}) -> Afantasticalscenefeaturingamajesticcastlewithtower.png
11+
assistant >

‎main.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
def create_new_thread():
3535
global current_thread
3636
current_thread = api.create_thread()
37-
return "New thread created."
37+
logger.reset_logs()
38+
return []
3839

3940

4041
create_new_thread()
@@ -162,16 +163,20 @@ def stream_worker(assistant_id, thread_id, event_handler):
162163
# history[-1][1] = wrap_latex_with_markdown(history[-1][1])
163164
yield history
164165

165-
files = extract_file_paths(history[-1][1])
166-
for file in files:
167-
file_path = get_file_path(file)
168-
if os.path.exists(file_path):
169-
history.append((None, (file_path,)))
170-
yield history
166+
# files = extract_file_paths(history[-1][1])
167+
# for file in files:
168+
# file_path = get_file_path(file)
169+
# if os.path.exists(file_path):
170+
# history.append((None, (file_path,)))
171+
# yield history
171172

172173
# Final flush of images
173174
while len(eh.images) > 0:
174-
history.append((None, (eh.images.pop(),)))
175+
file = eh.images.pop()
176+
file_path = get_file_path(file)
177+
if os.path.exists(file_path):
178+
history.append((None, file_path))
179+
history.append((None, (file_path,)))
175180
yield history
176181

177182
initial_thread.join()
@@ -297,7 +302,7 @@ def main_interface():
297302
"Create New Thread", size="lg"
298303
)
299304

300-
new_thread_button.click(create_new_thread, [], None)
305+
new_thread_button.click(create_new_thread, [], [chatbot])
301306

302307
chat_msg = chat_input.submit(
303308
ask_assistant,

‎playground/assistant_actions/fal_actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def create_image_with_fal(
1414
model="fal-ai/flux-pro",
1515
image_size="landscape_4_3",
1616
num_inference_steps=28,
17-
guidance_scale=3.5,
17+
guidance_scale=20.0,
1818
seed=222,
1919
):
2020
"""

‎playground/assistant_actions/image_actions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from playground.actions_manager import agent_action
88
from playground.global_values import GlobalValues
9+
import re
910

1011
load_dotenv()
1112

@@ -37,7 +38,7 @@ def create_image(prompt, model="dall-e-3", size="1024x1024", quality="standard",
3738
# Download the image
3839
image_response = requests.get(image_url)
3940
if image_response.status_code == 200:
40-
local_filename = f"{prompt.replace(' ', '_').replace(',','')[:50]}.png"
41+
local_filename = re.sub(r"[^\w\-.]", "", prompt)[:50] + ".png"
4142
local_path = os.path.join(
4243
GlobalValues.ASSISTANTS_WORKING_FOLDER, local_filename
4344
)

‎playground/assistants_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def on_image_file_done(self, image_file) -> None:
112112
print(f"File saved as {image_file}")
113113
self._images += [image_file]
114114

115+
def on_image_file(self, image_file) -> None:
116+
self._images += [image_file]
117+
115118
def on_tool_call_created(self, tool_call):
116119
if tool_call.type == "code_interpreter":
117120
print("# >>> Code Interpreter", flush=True)
@@ -159,6 +162,8 @@ def handle_requires_action(
159162
for c in el.content:
160163
if hasattr(c, "image_file"):
161164
self.on_image_file_done(c.image_file)
165+
elif ".png" in output:
166+
self.on_image_file(output)
162167

163168
tool_outputs.append(
164169
{"tool_call_id": tool.id, "output": str(output)}

‎storyboard_images.db

-8 KB
Binary file not shown.

0 commit comments

Comments
 (0)