Divya196 commited on
Commit
0e7b369
·
verified ·
1 Parent(s): 308c105

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +71 -0
  2. employee.db +0 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+
4
+ import streamlit as st
5
+ import os
6
+ import sqlite3
7
+
8
+ import google.generativeai as genai
9
+
10
+ #Configure genai key
11
+
12
+ genai.configure(api_key = os.getenv('GOOGLE_API_KEY'))
13
+
14
+ #Function to load google gemini model
15
+
16
+ def get_gemini_response(question,prompt):
17
+ model = genai.GenerativeModel('gemini-pro')
18
+ response = model.generate_content([prompt[0],question])
19
+ return response.text
20
+
21
+ #Function to retrieve query from the database
22
+
23
+ def read_sql_query(sql,db):
24
+ conn = sqlite3.connect(db)
25
+ cur = conn.cursor()
26
+ cur.execute(sql)
27
+ rows = cur.fetchall()
28
+ conn.commit()
29
+ conn.close()
30
+ for row in rows:
31
+ print(row)
32
+ return rows
33
+
34
+ #Defining prompt
35
+
36
+ prompt=[
37
+ """
38
+ You are an expert in converting English questions to SQL query!
39
+ The SQL database has the name EMPLOYEE and has the following columns - NAME, TEAM,
40
+ DOMAIN \n\nFor example,\nExample 1 - How many entries of records are present?,
41
+ the SQL command will be something like this SELECT COUNT(*) FROM EMPLOYEE ;
42
+ \nExample 2 - Tell me all the employees working in MLOPS team?,
43
+ the SQL command will be something like this SELECT * FROM EMPLOYEE
44
+ where TEAM="MLOPS";
45
+ also the sql code should not have ``` in beginning or end and sql word in output
46
+
47
+ """
48
+
49
+
50
+ ]
51
+
52
+ #streamlit Application
53
+
54
+ st.set_page_config(page_title = "I can retrieve any SQL query")
55
+ st.header("Gemini App to Retrieve SQL Data")
56
+
57
+ question = st.text_input("Input : ", key = "input")
58
+
59
+ submit = st.button("Ask the Question")
60
+
61
+ #if submit button is clicked
62
+
63
+ if submit:
64
+ response = get_gemini_response(question,prompt)
65
+ print(response)
66
+ response = read_sql_query(response,"employee.db")
67
+ st.subheader("THE RESPONSE IS")
68
+ for row in response:
69
+ print(row)
70
+ st.header(row)
71
+
employee.db ADDED
Binary file (8.19 kB). View file
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv