baconnier commited on
Commit
aa0bda3
Β·
verified Β·
1 Parent(s): 8d4adac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -69,7 +69,16 @@ class ArtExplorer:
69
  max_tokens=2048
70
  )
71
  print("Received response from LLM")
72
- result = json.loads(response.choices[0].message.content)
 
 
 
 
 
 
 
 
 
73
  return result
74
  except Exception as e:
75
  print(f"Error in LLM response: {str(e)}")
@@ -109,17 +118,16 @@ class ArtExplorer:
109
 
110
  with gr.Row():
111
  style_select = gr.Dropdown(
 
112
  multiselect=True,
113
- label="Artistic Styles"
 
114
  )
115
  style_explanation = gr.Markdown()
116
  style_zoom = gr.Button("πŸ” Zoom Styles")
117
 
118
  def initial_search(query):
119
- """
120
- Handle the initial search query and return properly formatted outputs for Gradio
121
- Returns individual values instead of a dictionary for Gradio components
122
- """
123
  config = self.get_llm_response(query)
124
  temporal_config = config["axis_configurations"]["temporal"]["current_zoom"]
125
  geographical_config = config["axis_configurations"]["geographical"]["current_zoom"]
@@ -127,7 +135,7 @@ class ArtExplorer:
127
 
128
  map_fig = self.create_map(geographical_config["locations"])
129
 
130
- # Return individual values in the order expected by Gradio
131
  return (
132
  temporal_config["range"], # time_slider
133
  map_fig, # map_plot
@@ -138,9 +146,7 @@ class ArtExplorer:
138
  )
139
 
140
  def zoom_axis(query, axis_name, current_value):
141
- """
142
- Handle zoom events for any axis with proper return formatting
143
- """
144
  self.current_state["zoom_level"] += 1
145
  config = self.get_llm_response(
146
  query,
@@ -208,7 +214,7 @@ def main():
208
  demo.launch(
209
  server_name="0.0.0.0",
210
  server_port=7860,
211
- share=True # Set to True to create a public link
212
  )
213
 
214
  if __name__ == "__main__":
 
69
  max_tokens=2048
70
  )
71
  print("Received response from LLM")
72
+
73
+ # Clean and parse the response
74
+ content = response.choices[0].message.content.strip()
75
+ try:
76
+ result = json.loads(content)
77
+ except json.JSONDecodeError as e:
78
+ print(f"JSON parsing error: {str(e)}")
79
+ print(f"Raw content: {content}")
80
+ return self.get_default_response()
81
+
82
  return result
83
  except Exception as e:
84
  print(f"Error in LLM response: {str(e)}")
 
118
 
119
  with gr.Row():
120
  style_select = gr.Dropdown(
121
+ choices=["Classical", "Modern"], # Set initial choices
122
  multiselect=True,
123
+ label="Artistic Styles",
124
+ allow_custom_value=True # Allow new values
125
  )
126
  style_explanation = gr.Markdown()
127
  style_zoom = gr.Button("πŸ” Zoom Styles")
128
 
129
  def initial_search(query):
130
+ """Handle the initial search query"""
 
 
 
131
  config = self.get_llm_response(query)
132
  temporal_config = config["axis_configurations"]["temporal"]["current_zoom"]
133
  geographical_config = config["axis_configurations"]["geographical"]["current_zoom"]
 
135
 
136
  map_fig = self.create_map(geographical_config["locations"])
137
 
138
+ # Return values directly in the order expected by Gradio
139
  return (
140
  temporal_config["range"], # time_slider
141
  map_fig, # map_plot
 
146
  )
147
 
148
  def zoom_axis(query, axis_name, current_value):
149
+ """Handle zoom events for any axis"""
 
 
150
  self.current_state["zoom_level"] += 1
151
  config = self.get_llm_response(
152
  query,
 
214
  demo.launch(
215
  server_name="0.0.0.0",
216
  server_port=7860,
217
+ share=True
218
  )
219
 
220
  if __name__ == "__main__":