SVashishta1 commited on
Commit
028022d
·
1 Parent(s): 2feba09
Files changed (2) hide show
  1. app.py +18 -0
  2. backend/vector_db.py +1 -49
app.py CHANGED
@@ -16,6 +16,7 @@ from io import BytesIO
16
  import speech_recognition as sr
17
  from gtts import gTTS
18
  import re
 
19
 
20
  # Load environment variables
21
  load_dotenv()
@@ -892,6 +893,23 @@ def flush_databases():
892
 
893
  return "\n".join(result)
894
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
895
  # Create Gradio interface
896
  with gr.Blocks(title="AI Document Analysis & Voice Assistant") as demo:
897
  gr.Markdown("# 🤖 AI Document Analysis & Voice Assistant")
 
16
  import speech_recognition as sr
17
  from gtts import gTTS
18
  import re
19
+ import importlib.util
20
 
21
  # Load environment variables
22
  load_dotenv()
 
893
 
894
  return "\n".join(result)
895
 
896
+ # At the beginning of app.py, after the imports
897
+ # Add this code to monkey patch the vector_db module
898
+ try:
899
+ from backend.vector_db import ChromaVectorDB
900
+ except NameError as e:
901
+ if "response" in str(e):
902
+ # If the error is about 'response' not being defined, fix the module
903
+ import backend.vector_db
904
+
905
+ # Remove the problematic code
906
+ if hasattr(backend.vector_db, 'response'):
907
+ delattr(backend.vector_db, 'response')
908
+
909
+ # Reload the module
910
+ importlib.reload(backend.vector_db)
911
+ from backend.vector_db import ChromaVectorDB
912
+
913
  # Create Gradio interface
914
  with gr.Blocks(title="AI Document Analysis & Voice Assistant") as demo:
915
  gr.Markdown("# 🤖 AI Document Analysis & Voice Assistant")
backend/vector_db.py CHANGED
@@ -2,11 +2,6 @@ import os
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"):
@@ -66,47 +61,4 @@ class ChromaVectorDB:
66
  return True
67
  except Exception as e:
68
  print(f"Error resetting collection: {str(e)}")
69
- return False
70
-
71
- # Create sample data
72
- data = pd.DataFrame({
73
- 'Month': ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
74
- 'Value': [10, 15, 13, 17, 20, 25]
75
- })
76
-
77
- # Create a simple bar chart
78
- fig = px.bar(data, x='Month', y='Value', title='Test Visualization')
79
-
80
- # Configure the figure
81
- fig.update_layout(
82
- autosize=True,
83
- width=800,
84
- height=500
85
- )
86
-
87
- # Try both methods
88
- try:
89
- # Method 1: Convert to image
90
- print("Visualization requested, attempting to create plot...")
91
- # ...
92
- print(f"Created figure with width={fig.layout.width}, height={fig.layout.height}")
93
- # ...
94
- print("Converting figure to image...")
95
- img_bytes = fig.to_image(format="png", width=fig.layout.width, height=fig.layout.height, scale=2)
96
- print("Image conversion successful")
97
- # ...
98
- except Exception as viz_error:
99
- print(f"Visualization error: {str(viz_error)}")
100
- traceback.print_exc()
101
- response += f"\n\n**Visualization Error:** {str(viz_error)}"
102
-
103
- try:
104
- # Method 2: Convert to HTML
105
- html = pio.to_html(fig, full_html=False, include_plotlyjs='cdn')
106
- print("HTML conversion successful")
107
- except Exception as e:
108
- print(f"HTML conversion failed: {str(e)}")
109
-
110
- # Replace the image conversion with HTML
111
- html_plot = pio.to_html(fig, full_html=False, include_plotlyjs='cdn')
112
- response += f"\n\n<div style='width:100%; height:700px;'>{html_plot}</div>"
 
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"):
 
61
  return True
62
  except Exception as e:
63
  print(f"Error resetting collection: {str(e)}")
64
+ return False