Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from dotenv import load_dotenv
|
2 |
-
load_dotenv()
|
3 |
|
4 |
import streamlit as st
|
5 |
from PyPDF2 import PdfReader
|
@@ -12,7 +12,6 @@ from langchain_google_genai import ChatGoogleGenerativeAI
|
|
12 |
from langchain.chains.question_answering import load_qa_chain
|
13 |
from langchain.prompts import PromptTemplate
|
14 |
from PIL import Image
|
15 |
-
import sqlite3
|
16 |
|
17 |
## Function to load gemini pro model and get responses
|
18 |
def get_gemini_response(input, image=None):
|
@@ -63,20 +62,11 @@ def user_input(user_question):
|
|
63 |
response = chain({"input_documents":docs, "question": user_question}, return_only_outputs=True)
|
64 |
return response["output_text"]
|
65 |
|
66 |
-
def read_sql_query(sql, db):
|
67 |
-
conn = sqlite3.connect(db)
|
68 |
-
cur = conn.cursor()
|
69 |
-
cur.execute(sql)
|
70 |
-
rows = cur.fetchall()
|
71 |
-
conn.commit()
|
72 |
-
conn.close()
|
73 |
-
return rows
|
74 |
-
|
75 |
def main():
|
76 |
st.set_page_config(page_title='Combined Demo')
|
77 |
st.header("Combined Application")
|
78 |
|
79 |
-
app_mode = st.sidebar.selectbox("Choose the App Mode", ["Gemini Q&A", "PDF Q&A", "Gemini Image"
|
80 |
|
81 |
if app_mode == "Gemini Q&A":
|
82 |
st.subheader("Gemini LLM Application")
|
@@ -114,28 +104,5 @@ def main():
|
|
114 |
st.subheader("The Response is :")
|
115 |
st.write(response)
|
116 |
|
117 |
-
elif app_mode == "Gemini SQL":
|
118 |
-
st.subheader("Gemini LLM Application for SQL")
|
119 |
-
question = st.text_input("Input")
|
120 |
-
if st.button("Ask the question"):
|
121 |
-
prompt = [
|
122 |
-
"""
|
123 |
-
You are an expert in converting English questions to SQL query!
|
124 |
-
The SQL database has the name STUDENT and has the following columns - NAME, CLASS,
|
125 |
-
SECTION \n\nFor example,\nExample 1 - How many entries of records are present?,
|
126 |
-
the SQL command will be something like this SELECT COUNT(*) FROM STUDENT ;
|
127 |
-
\nExample 2 - Tell me all the students studying in Data Science class?,
|
128 |
-
the SQL command will be something like this SELECT * FROM STUDENT
|
129 |
-
where CLASS="Data Science";
|
130 |
-
also the sql code should not have ``` in beginning or end and sql word in output
|
131 |
-
"""
|
132 |
-
]
|
133 |
-
response = get_gemini_response(question, prompt)
|
134 |
-
st.subheader("The Response is :")
|
135 |
-
st.write(response)
|
136 |
-
st.subheader("SQL Query Result:")
|
137 |
-
result = read_sql_query(response, "student.db")
|
138 |
-
st.write(result)
|
139 |
-
|
140 |
if __name__ == "__main__":
|
141 |
main()
|
|
|
1 |
from dotenv import load_dotenv
|
2 |
+
load_dotenv() # Load all env variables
|
3 |
|
4 |
import streamlit as st
|
5 |
from PyPDF2 import PdfReader
|
|
|
12 |
from langchain.chains.question_answering import load_qa_chain
|
13 |
from langchain.prompts import PromptTemplate
|
14 |
from PIL import Image
|
|
|
15 |
|
16 |
## Function to load gemini pro model and get responses
|
17 |
def get_gemini_response(input, image=None):
|
|
|
62 |
response = chain({"input_documents":docs, "question": user_question}, return_only_outputs=True)
|
63 |
return response["output_text"]
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
def main():
|
66 |
st.set_page_config(page_title='Combined Demo')
|
67 |
st.header("Combined Application")
|
68 |
|
69 |
+
app_mode = st.sidebar.selectbox("Choose the App Mode", ["Gemini Q&A", "PDF Q&A", "Gemini Image"])
|
70 |
|
71 |
if app_mode == "Gemini Q&A":
|
72 |
st.subheader("Gemini LLM Application")
|
|
|
104 |
st.subheader("The Response is :")
|
105 |
st.write(response)
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
if __name__ == "__main__":
|
108 |
main()
|