SVashishta1 commited on
Commit
b37a516
·
1 Parent(s): e2df3d3
Files changed (1) hide show
  1. backend/vector_db.py +49 -1
backend/vector_db.py CHANGED
@@ -2,6 +2,11 @@ import os
2
  import chromadb
3
  from typing import List, Dict, Any
4
  import hashlib
 
 
 
 
 
5
 
6
  class ChromaVectorDB:
7
  def __init__(self, db_path: str = "./data/chroma_db"):
@@ -49,4 +54,47 @@ class ChromaVectorDB:
49
  )
50
 
51
  if results and results['ids']:
52
- self.collection.delete(ids=results['ids'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import chromadb
3
  from typing import List, Dict, Any
4
  import hashlib
5
+ import plotly.express as px
6
+ import pandas as pd
7
+ import base64
8
+ import plotly.io as pio
9
+ import traceback
10
 
11
  class ChromaVectorDB:
12
  def __init__(self, db_path: str = "./data/chroma_db"):
 
54
  )
55
 
56
  if results and results['ids']:
57
+ self.collection.delete(ids=results['ids'])
58
+
59
+ # Create sample data
60
+ data = pd.DataFrame({
61
+ 'Month': ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
62
+ 'Value': [10, 15, 13, 17, 20, 25]
63
+ })
64
+
65
+ # Create a simple bar chart
66
+ fig = px.bar(data, x='Month', y='Value', title='Test Visualization')
67
+
68
+ # Configure the figure
69
+ fig.update_layout(
70
+ autosize=True,
71
+ width=800,
72
+ height=500
73
+ )
74
+
75
+ # Try both methods
76
+ try:
77
+ # Method 1: Convert to image
78
+ print("Visualization requested, attempting to create plot...")
79
+ # ...
80
+ print(f"Created figure with width={fig.layout.width}, height={fig.layout.height}")
81
+ # ...
82
+ print("Converting figure to image...")
83
+ img_bytes = fig.to_image(format="png", width=fig.layout.width, height=fig.layout.height, scale=2)
84
+ print("Image conversion successful")
85
+ # ...
86
+ except Exception as viz_error:
87
+ print(f"Visualization error: {str(viz_error)}")
88
+ traceback.print_exc()
89
+ response += f"\n\n**Visualization Error:** {str(viz_error)}"
90
+
91
+ try:
92
+ # Method 2: Convert to HTML
93
+ html = pio.to_html(fig, full_html=False, include_plotlyjs='cdn')
94
+ print("HTML conversion successful")
95
+ except Exception as e:
96
+ print(f"HTML conversion failed: {str(e)}")
97
+
98
+ # Replace the image conversion with HTML
99
+ html_plot = pio.to_html(fig, full_html=False, include_plotlyjs='cdn')
100
+ response += f"\n\n<div style='width:100%; height:700px;'>{html_plot}</div>"