devopscloudram/AIZomato
0
1from dotenv import load_dotenv2load_dotenv() ## load all the environemnt variables3 4import streamlit as st5import os6import sqlite37import pandas as pd8 9import google.generativeai as genai10## Configure Genai Key11 12genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))13 14## Function To Load Google Gemini Model and provide queries as response15 16def get_gemini_response(question,prompt):17 model=genai.GenerativeModel('gemini-pro')18 response=model.generate_content([prompt[0],question])19 return response.text20 21## Fucntion To retrieve query from the database22 23def 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 rows33 34## Define Your Prompt35prompt=[36 """37 You are an expert in converting English questions to SQL query!38 The SQL database has the name ZomatoSales and has the following columns - 39 OrderID,OrderDate,CustomerName,RestaurantName,TotalAmount,PaymentMethod,40 SECTION \n\nFor example,\nExample 1 - How many entries of records are present?, 41 the SQL command will be something like this SELECT COUNT(*) FROM ZomatoSales ;42 \nExample 2 - Tell me all the CustomerName who bought orders using cash, 43 the SQL command will be something like this SELECT * FROM ZomatoSales, 44 where PaymentMethod="Cash"; 45 also the sql code should not have ``` in beginning or end and sql word in output46 47 """48]49 50## Streamlit App51 52st.set_page_config(page_title="I can report Zomato Sales")53st.header("Ramz GenAI App - Zomato Sales")54 55question=st.text_input("Type which sale info you want?: ",key="input")56 57submit=st.button("Ask the question :question:")58 59# if submit is clicked60if submit:61 response=get_gemini_response(question,prompt)62 print(response)63 response=read_sql_query(response,"zomatoSales.db")64 st.subheader("The Response is")65 df = pd.DataFrame(response)66# print(df)67 st.write(df) 68#for row in response:69# print(row)70# st.header(row)