Uddancode commited on
Commit
4e77096
·
verified ·
1 Parent(s): fd49787

Upload 3 files

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