Spaces:
Sleeping
Sleeping
Alexandros Popov
commited on
Commit
·
6f3fb70
1
Parent(s):
23afe01
prepared for gradio.
Browse files
main.py
CHANGED
@@ -96,7 +96,14 @@ and pricesely point out items that are out of time.
|
|
96 |
"""
|
97 |
|
98 |
@observe(name="image_captionning", capture_input=False, as_type="generation")
|
99 |
-
def image_caption(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
response = client.responses.create(
|
102 |
model="o4-mini-2025-04-16",
|
@@ -260,7 +267,7 @@ async def main(image_path, location, year) -> None:
|
|
260 |
print(f"Working in {working_directory}")
|
261 |
|
262 |
with trace("LLM as a judge"):
|
263 |
-
picture_description = image_caption(image_path)
|
264 |
historical_grounding = get_historical_grounding(picture_description, location, year)
|
265 |
picture_designer_agent = define_picture_designer_agent(image_path, working_directory)
|
266 |
|
@@ -305,24 +312,34 @@ async def main(image_path, location, year) -> None:
|
|
305 |
|
306 |
print(f"Final story outline: {latest_outline}")
|
307 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
|
310 |
if __name__ == "__main__":
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
# gr.Textbox(label="Prompt"),
|
319 |
-
# gr.Slider(minimum=-2000, maximum=2000, value=1900, label="Year")
|
320 |
-
# ],
|
321 |
-
# outputs=[
|
322 |
-
# gr.Image(type="filepath", label="Generated Image"),
|
323 |
-
# gr.Textbox(label="Generated Text")
|
324 |
-
# ],
|
325 |
-
# title="Scene Rewind",
|
326 |
-
# description="Upload an image, provide a prompt, and select a year to travel back in time!"
|
327 |
-
# )
|
328 |
-
# iface.launch()
|
|
|
96 |
"""
|
97 |
|
98 |
@observe(name="image_captionning", capture_input=False, as_type="generation")
|
99 |
+
def image_caption(image, working_directory):
|
100 |
+
|
101 |
+
if isinstance(image, np.ndarray):
|
102 |
+
temp_image_path = os.path.join(working_directory, "temp_input_image.png")
|
103 |
+
imageio.imwrite(temp_image_path, image)
|
104 |
+
image_path = temp_image_path
|
105 |
+
else:
|
106 |
+
image_path = image
|
107 |
|
108 |
response = client.responses.create(
|
109 |
model="o4-mini-2025-04-16",
|
|
|
267 |
print(f"Working in {working_directory}")
|
268 |
|
269 |
with trace("LLM as a judge"):
|
270 |
+
picture_description = image_caption(image_path, working_directory)
|
271 |
historical_grounding = get_historical_grounding(picture_description, location, year)
|
272 |
picture_designer_agent = define_picture_designer_agent(image_path, working_directory)
|
273 |
|
|
|
312 |
|
313 |
print(f"Final story outline: {latest_outline}")
|
314 |
|
315 |
+
# Create Gradio interface
|
316 |
+
def create_interface():
|
317 |
+
iface = gr.Interface(
|
318 |
+
fn=main, # Use wrapper function
|
319 |
+
inputs=[
|
320 |
+
gr.Image(type="numpy", label="Input Image"),
|
321 |
+
gr.Textbox(label="Location/Prompt", placeholder="e.g., Paris, Times Square, etc."),
|
322 |
+
gr.Slider(minimum=-2000, maximum=2000, value=1900, step=1, label="Target Year")
|
323 |
+
],
|
324 |
+
outputs=[
|
325 |
+
gr.Image(type="filepath", label="Historical Scene"),
|
326 |
+
gr.Textbox(label="Historical Description")
|
327 |
+
],
|
328 |
+
title="🕰️ Scene Rewind - Historical Time Travel",
|
329 |
+
description="Upload an image of a location, specify the place, and select a year to see how it might have looked in the past!",
|
330 |
+
examples=[
|
331 |
+
["images/paris.png", "Paris", 1700],
|
332 |
+
["images/newyork.jpg", "New York City", 1850],
|
333 |
+
] if False else None # Set to True if you have example images
|
334 |
+
)
|
335 |
+
return iface
|
336 |
|
337 |
|
338 |
if __name__ == "__main__":
|
339 |
+
# Option 1: Launch Gradio interface
|
340 |
+
interface = create_interface()
|
341 |
+
interface.launch(
|
342 |
+
share=False, # Set to True if you want a public link
|
343 |
+
server_name="127.0.0.1",
|
344 |
+
server_port=7860
|
345 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|