- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.py
More file actions
Latest commit
86 lines (68 loc) · 2.74 KB
/
Copy pathtempCodeRunnerFile.py
File metadata and controls
86 lines (68 loc) · 2.74 KB
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
fromragdash.chromadbimportChromaDB_VectorStore
fromragdash.groqimportGroq
fromragdash.exceptionsimportValidationError
importos
importstreamlitasst
fromdotenvimportload_dotenv
# Load environment variables from .env file
load_dotenv()
classMyRAGdash(ChromaDB_VectorStore, Groq):
def__init__(self, config=None):
# Initialize both base classes
ChromaDB_VectorStore.__init__(self, config=config)
Groq.__init__(self, config=config)
# Usage example
config= {
'db_user': os.getenv('DB_USER'),
'db_password': os.getenv('DB_PASSWORD'),
'db_host': os.getenv('DB_HOST'),
'db_name': os.getenv('DB_NAME')
}
print(config)
rd=MyRAGdash(config=config)
try:
rd.connect_to_mysql(host=config['db_host'], dbname=config['db_name'], user=config['db_user'], password=config['db_password'], port=3306)
exceptExceptionase:
st.error(f"Error connecting to the database: {e}")
st.stop()
# data ka extarction
my_questions= {
"bar": "extract the data appropriate for bar chart",
"pie": "extract the data appropriate for pie chart",
"line": "extract the data appropriate for line chart",
"scatter": "extract the data appropriate for scatter chart",
"bubble": "extract the data appropriate for bubble chart",
"heatmap": "extract the data appropriate for heatmap chart",
"box": "extract the data appropriate for box chart",
"histogram": "extract the data appropriate for histogram chart",
}
results= {}
# Generate SQL queries and DataFrames for each chart type with error handling
forchart_type, questioninmy_questions.items():
try:
sql=rd.generate_sql(question)
df=rd.run_sql(sql)
# Store DataFrame and SQL in results
results[chart_type] = {
"df": df,
"sql": sql
}
# Display DataFrame
st.dataframe(df, use_container_width=True)
exceptValidationErrorase:
st.error(f"Validation error for {chart_type} chart: {e}")
results[chart_type] =None# Store None to indicate failure
exceptExceptionase:
st.error(f"Error processing {chart_type} chart: {e}")
results[chart_type] =None# Store None to indicate failure
# Generate Plotly code and figures with error handling
forchart_typeinresults:
ifresults[chart_type] isnotNone:
try:
df=results[chart_type]["df"]
sql=results[chart_type]["sql"]
code=rd.generate_plotly_code(question=my_questions[chart_type], sql=sql, df=df, type_c=chart_type)
fig=rd.get_plotly_figure(plotly_code=code, df=df)
st.plotly_chart(fig, use_container_width=True)
exceptExceptionase:
st.error(f"Error generating {chart_type} plot: {e}")