yourownvibhore commited on
Commit
b4b8960
·
verified ·
1 Parent(s): 8f91e4a

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +52 -0
  2. requirements.txt +7 -0
  3. sql.py +26 -0
  4. student.db +0 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+ import streamlit as st
4
+ import os
5
+ import google.generativeai as genai
6
+ from PIL import Image
7
+ import sqlite3
8
+
9
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
+ # load gemini model
11
+ def get_gemini_response(question,prompt):
12
+ model=genai.GenerativeModel("gemini-pro")
13
+ response=model.generate_content([prompt[0],question])
14
+ return response.text
15
+
16
+ def read_sql_query(sql,db):
17
+ connection=sqlite3.connect('student.db')
18
+ cursor=connection.cursor()
19
+ cursor.execute(sql)
20
+ rows=cursor.fetchall()
21
+ connection.commit()
22
+ connection.close()
23
+ for row in rows:
24
+ print(row)
25
+ return rows
26
+
27
+ prompt=[
28
+ """
29
+ You are an expert in converting English questions to SQL query!
30
+ The SQL database has the name student and has the following columns - name, roll,
31
+ section,marks \n\nFor example,\nExample 1 - How many entries of records are present?,
32
+ the SQL command will be something like this SELECT COUNT(*) FROM student ;
33
+ \nExample 2 - Tell me all the students studying in A section?,
34
+ the SQL command will be something like this SELECT * FROM student
35
+ where section="A";
36
+ also the sql code should not have ``` in beginning or end and sql word in output
37
+ """
38
+ ]
39
+
40
+
41
+ st.set_page_config(page_title="SQL Query Generator",page_icon="📊")
42
+ st.title("SQL Query Generator")
43
+ st.write("This app generates SQL queries based on the questions asked by the user.")
44
+ question=st.text_input("Enter your question here:",key="input")
45
+ submit=st.button("Generate SQL Query")
46
+
47
+ if submit:
48
+ response=get_gemini_response(question,prompt)
49
+ st.write(response)
50
+ rows=read_sql_query(response,"student.db")
51
+ for row in rows:
52
+ st.write(row)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ langchain
5
+ PyPDF2
6
+ faiss-cpu
7
+ langchain_google_genai
sql.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+
3
+ connection=sqlite3.connect('student.db')
4
+ cursor=connection.cursor()
5
+ table_info="""
6
+
7
+ CREATE TABLE student(name TEXT,roll TEXT,section TEXT,marks INT)
8
+
9
+ """
10
+
11
+ cursor.execute(table_info)
12
+
13
+ cursor.execute("INSERT INTO student VALUES('Rahul','10','A',90)")
14
+ cursor.execute("INSERT INTO student VALUES('MOHIT','19','B',80)")
15
+ cursor.execute("INSERT INTO student VALUES('RAJ','13','C',70)")
16
+ cursor.execute("INSERT INTO student VALUES('POHIT','18','D',60)")
17
+
18
+ print("Data inserted successfully")
19
+
20
+ data=cursor.execute("SELECT * FROM student")
21
+
22
+ for i in data:
23
+ print(i)
24
+
25
+ connection.commit()
26
+ connection.close()
student.db ADDED
Binary file (8.19 kB). View file