suriya7 commited on
Commit
b1880bd
·
verified ·
1 Parent(s): 069e5e4

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +100 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import google.generativeai as genai
3
+ from dotenv import load_dotenv
4
+ import os
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
+
9
+ # Configure GenerativeAI with API key
10
+ genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
11
+
12
+ def main():
13
+ # Function to generate SQL query based on prompt input
14
+ def gemini_ans(prompt_input):
15
+ model = genai.GenerativeModel('gemini-pro')
16
+ response = model.generate_content([prompt_input])
17
+ return response.text
18
+
19
+ # Set page configuration
20
+ st.set_page_config(page_title='SQL Query Generator', page_icon=':robot:')
21
+
22
+ # Header section
23
+ st.markdown(
24
+ """
25
+ <style>
26
+ .header {
27
+ padding: 20px;
28
+ background-color: #f0f0f0;
29
+ border-radius: 10px;
30
+ margin-bottom: 20px;
31
+ color: black;
32
+ }
33
+ .header h1, .header h3 {
34
+ margin: 0;
35
+ color: black;
36
+ }
37
+ </style>
38
+ """
39
+ , unsafe_allow_html=True)
40
+
41
+ st.markdown(
42
+ """
43
+ <div class="header">
44
+ <h1 style="text-align: center;">SQL Query Generator 🤖</h1>
45
+ <h3 style="text-align: center;">Generate SQL queries with ease!</h3>
46
+ <p style="text-align: center;">This tool allows you to generate SQL queries based on your prompt.</p>
47
+ </div>
48
+ """
49
+ , unsafe_allow_html=True)
50
+
51
+ # Text area for input
52
+ input_text = st.text_area('Enter your query...')
53
+
54
+ # Generate SQL Query button
55
+ submit = st.button('Generate SQL Query', key='generate_button')
56
+
57
+ # Prompts for model responses
58
+ prompt = """
59
+ You are an English to SQL language translator. Using the given text here {en},
60
+ write a SQL query only without making any mistakes.
61
+ """
62
+
63
+ prompt1 = """
64
+ What would be the expected response of this query snippet:
65
+ ```
66
+ {query}
67
+ ```
68
+ Provide a sample tabular response with no explanation.
69
+ """
70
+
71
+ prompt2 = """
72
+ Explain the SQL query:
73
+ ```
74
+ {query}
75
+ ```
76
+ Please provide the simplest explanation.
77
+ """
78
+
79
+ # Handle button click event
80
+ if submit:
81
+ with st.spinner('Generating SQL Query...'):
82
+ # Generate SQL query
83
+ sql_query = gemini_ans(prompt.format(en=input_text))
84
+ st.header('Model Response')
85
+ st.success("Generated SQL Query Successfully!")
86
+ st.write(sql_query)
87
+
88
+ # Generate sample expected output
89
+ sql_table = gemini_ans(prompt1.format(query=sql_query))
90
+ st.success('Sample Expected Output')
91
+ st.markdown(sql_table)
92
+
93
+ # Generate explanation of the given query
94
+ sql_explanation = gemini_ans(prompt2.format(query=sql_query))
95
+ st.success('Explanation of the Given Query')
96
+ st.markdown(sql_explanation)
97
+
98
+ # Execute main function
99
+ if __name__ == "__main__":
100
+ main()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ google-generativeai
2
+ streamlit
3
+ python-dotenv