|
import streamlit as st |
|
import google.generativeai as genai |
|
from dotenv import load_dotenv |
|
import os |
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
genai.configure(api_key=os.getenv('GOOGLE_API_KEY')) |
|
|
|
def main(): |
|
|
|
def gemini_ans(prompt_input): |
|
model = genai.GenerativeModel('gemini-pro') |
|
response = model.generate_content([prompt_input]) |
|
return response.text |
|
|
|
|
|
st.set_page_config(page_title='SQL Query Generator', page_icon=':robot:') |
|
|
|
|
|
st.markdown( |
|
""" |
|
<style> |
|
.header { |
|
padding: 20px; |
|
background-color: #f0f0f0; |
|
border-radius: 10px; |
|
margin-bottom: 20px; |
|
color: black; |
|
} |
|
.header h1, .header h3 { |
|
margin: 0; |
|
color: black; |
|
} |
|
</style> |
|
""" |
|
, unsafe_allow_html=True) |
|
|
|
st.markdown( |
|
""" |
|
<div class="header"> |
|
<h1 style="text-align: center;">SQL Query Generator π€</h1> |
|
<h3 style="text-align: center;">Generate SQL queries with ease!</h3> |
|
<p style="text-align: center;">This tool allows you to generate SQL queries based on your prompt.</p> |
|
</div> |
|
""" |
|
, unsafe_allow_html=True) |
|
|
|
|
|
input_text = st.text_area('Enter your query...') |
|
|
|
|
|
submit = st.button('Generate SQL Query', key='generate_button') |
|
|
|
|
|
prompt = """ |
|
You are an English to SQL language translator. Using the given text here {en}, |
|
write a SQL query only without making any mistakes. |
|
""" |
|
|
|
prompt1 = """ |
|
What would be the expected response of this query snippet: |
|
``` |
|
{query} |
|
``` |
|
Provide a sample tabular response with no explanation. |
|
""" |
|
|
|
prompt2 = """ |
|
Explain the SQL query: |
|
``` |
|
{query} |
|
``` |
|
Please provide the simplest explanation. |
|
""" |
|
|
|
|
|
if submit: |
|
with st.spinner('Generating SQL Query...'): |
|
|
|
sql_query = gemini_ans(prompt.format(en=input_text)) |
|
st.header('Model Response') |
|
st.success("Generated SQL Query Successfully!") |
|
st.write(sql_query) |
|
|
|
|
|
sql_table = gemini_ans(prompt1.format(query=sql_query)) |
|
st.success('Sample Expected Output') |
|
st.markdown(sql_table) |
|
|
|
|
|
sql_explanation = gemini_ans(prompt2.format(query=sql_query)) |
|
st.success('Explanation of the Given Query') |
|
st.markdown(sql_explanation) |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |
|
|