Encyclopedia / app.py
baconnier's picture
Update app.py
4244d2c verified
raw
history blame
2.65 kB
import gradio as gr
from art_explorer import ArtExplorer
from visualization import create_map_visualization, create_timeline_visualization
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
class ArtExplorerInterface:
def __init__(self):
self.explorer = ArtExplorer()
def explore(self, query: str, zoom_level: int) -> tuple:
# Get exploration results
response = self.explorer.explore_art_period(query, zoom_level)
if not response:
return "Error in exploration", None, None
# Create visualizations
map_fig = create_map_visualization(self.explorer.get_location_data())
timeline_fig = create_timeline_visualization(self.explorer.get_timeline_data())
# Format text response
text_response = f"""
Period: {response.time_period.name}
Years: {response.time_period.start_year} - {response.time_period.end_year}
Cultural Context:
{response.cultural_context}
Key Artists:
{', '.join(artist.name for artist in response.key_artists)}
Notable Works:
{', '.join(work.title for work in response.notable_works)}
Influence:
{response.influence_on_later_periods}
"""
return text_response, map_fig, timeline_fig
def create_interface(self):
with gr.Blocks(title="Art History Explorer") as interface:
gr.Markdown("# Art History Explorer")
with gr.Row():
query_input = gr.Textbox(
label="Enter your art history query",
placeholder="e.g., Italian Renaissance in Florence"
)
zoom_level = gr.Slider(
minimum=1,
maximum=5,
value=1,
step=1,
label="Zoom Level"
)
explore_btn = gr.Button("Explore")
with gr.Row():
text_output = gr.Textbox(
label="Exploration Results",
interactive=False
)
with gr.Row():
map_output = gr.Plot(label="Geographic Context")
timeline_output = gr.Plot(label="Historical Timeline")
explore_btn.click(
fn=self.explore,
inputs=[query_input, zoom_level],
outputs=[text_output, map_output, timeline_output]
)
return interface
def main():
app = ArtExplorerInterface()
interface = app.create_interface()
interface.launch(share=True)
if __name__ == "__main__":
main()