File size: 2,651 Bytes
d6a8ad7
4244d2c
 
 
c6219ec
4244d2c
 
8f7fdc3
4244d2c
 
 
c38a10f
4244d2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a48e4da
4244d2c
 
de35f25
a48e4da
 
4244d2c
de35f25
4244d2c
de35f25
4244d2c
 
 
 
 
 
de35f25
4244d2c
 
 
 
 
 
 
8d4adac
4244d2c
 
 
 
 
 
 
 
 
a48e4da
4244d2c
 
a7cc45c
 
4244d2c
 
 
a7cc45c
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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()