CoolFace
Apppublic

Sanc1403/TexttoSQLGenerativeAI

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
app.py49 linesDownload Raw Back to root
1from dotenv import load_dotenv2 3load_dotenv()4 5import streamlit as st6import os7import sqlite38 9import google.generativeai as genai10 11genai.configure(api_key = os.getenv("GOOGLE_API_KEY"))12 13def get_gemini_response(question, prompt):14    model = genai.GenerativeModel('gemini-pro')15    response = model.generate_content([prompt, question])16    return response.text17 18def read_sql_query(sql, db):19    conn = sqlite3.connect(db)20    curr = conn.cursor()21    curr.execute(sql)22    rows = curr.fetchall()23    conn.commit()24    conn.close()25    for row in rows:26        print(row[0])27    return rows28 29 30prompt = """You are an expert in converting english text to SQL query.31    I have a database with table named Student & have columns as32    Name, Class, Section. Please help me with this task.33    Sql code should not have these signs ``` before and after query.34    """35 36st.set_page_config(page_title="I can retrieve any SQL query")37st.header("Gemini App to retrieve SQL Data")38 39question = st.text_input("Input: ", key='input')40submit = st.button("Ask the question")41 42if submit:43    response = get_gemini_response(question, prompt)44    response = read_sql_query(response, 'student.db')45    st.subheader("The Response is: ")46    for row in response:47        print(response)48        print(row)49        st.header(row[0])