Update app.py
Browse files
app.py
CHANGED
|
@@ -5,12 +5,14 @@ import google.generativeai as genai
|
|
| 5 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
import streamlit as st
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
temperature = 0.3
|
| 11 |
pages = []
|
| 12 |
numPairs = 2
|
| 13 |
option = ''
|
|
|
|
| 14 |
optionCategory = ("Long QA Pairs", "MCQs", "Short QA Pairs")
|
| 15 |
|
| 16 |
load_dotenv()
|
|
@@ -20,18 +22,25 @@ model = ChatGoogleGenerativeAI(model="gemini-pro", temperature=temperature)
|
|
| 20 |
def LongQAPairs():
|
| 21 |
response = []
|
| 22 |
with st.spinner('Generating Long Question Answer Pairs...'):
|
| 23 |
-
response =getLongQAPairs(pages[0:len(pages) - 1], numPairs, model)
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
for qaPair in response:
|
| 26 |
with st.chat_message("user"):
|
| 27 |
st.write("Question : {}".format(qaPair['question']))
|
| 28 |
st.write("Answer : {}".format(qaPair['answer']))
|
| 29 |
|
|
|
|
| 30 |
def ShortQAPairs():
|
| 31 |
response = []
|
| 32 |
with st.spinner('Generating Short Question Answer Pairs...'):
|
| 33 |
response = getShortQAPairs(pages[0:len(pages) - 1], numPairs, model)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
| 35 |
for qaPair in response:
|
| 36 |
with st.chat_message("user"):
|
| 37 |
st.write("Question : {}".format(qaPair['question']))
|
|
@@ -43,9 +52,13 @@ def McqQAPairs():
|
|
| 43 |
with st.spinner('Generating MCQ Question Answer Pairs...'):
|
| 44 |
response = getMcqQAPairs(pages[0:len(pages) - 1], numPairs, model)
|
| 45 |
|
|
|
|
|
|
|
|
|
|
| 46 |
for qaPair in response:
|
| 47 |
with st.chat_message("user"):
|
| 48 |
-
st.radio(label=qaPair['question'],options=qaPair["options"],disabled=True,
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
with st.sidebar:
|
|
@@ -88,7 +101,12 @@ with st.container(border=True):
|
|
| 88 |
index=None,
|
| 89 |
placeholder="Select Category of Question Answer Pairs",
|
| 90 |
)
|
| 91 |
-
numPairs = st.number_input('Number of QA Pairs', min_value=1, max_value=20, step=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
if st.button("Generate", type="primary"):
|
| 94 |
if option == "Long QA Pairs" and len(pages) and option in optionCategory:
|
|
|
|
| 5 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
import streamlit as st
|
| 8 |
+
|
| 9 |
+
st.set_page_config(layout="wide", page_title="QA Pair Generation from Documents", page_icon='deep-learning.png')
|
| 10 |
|
| 11 |
temperature = 0.3
|
| 12 |
pages = []
|
| 13 |
numPairs = 2
|
| 14 |
option = ''
|
| 15 |
+
FileName= ''
|
| 16 |
optionCategory = ("Long QA Pairs", "MCQs", "Short QA Pairs")
|
| 17 |
|
| 18 |
load_dotenv()
|
|
|
|
| 22 |
def LongQAPairs():
|
| 23 |
response = []
|
| 24 |
with st.spinner('Generating Long Question Answer Pairs...'):
|
| 25 |
+
response = getLongQAPairs(pages[0:len(pages) - 1], numPairs, model)
|
| 26 |
+
|
| 27 |
+
if len(FileName) != 5:
|
| 28 |
+
downloadFile(response,FileName)
|
| 29 |
|
| 30 |
for qaPair in response:
|
| 31 |
with st.chat_message("user"):
|
| 32 |
st.write("Question : {}".format(qaPair['question']))
|
| 33 |
st.write("Answer : {}".format(qaPair['answer']))
|
| 34 |
|
| 35 |
+
|
| 36 |
def ShortQAPairs():
|
| 37 |
response = []
|
| 38 |
with st.spinner('Generating Short Question Answer Pairs...'):
|
| 39 |
response = getShortQAPairs(pages[0:len(pages) - 1], numPairs, model)
|
| 40 |
|
| 41 |
+
if len(FileName) !=5:
|
| 42 |
+
downloadFile(response, FileName)
|
| 43 |
+
|
| 44 |
for qaPair in response:
|
| 45 |
with st.chat_message("user"):
|
| 46 |
st.write("Question : {}".format(qaPair['question']))
|
|
|
|
| 52 |
with st.spinner('Generating MCQ Question Answer Pairs...'):
|
| 53 |
response = getMcqQAPairs(pages[0:len(pages) - 1], numPairs, model)
|
| 54 |
|
| 55 |
+
if len(FileName) != 5:
|
| 56 |
+
downloadFile(response,FileName)
|
| 57 |
+
|
| 58 |
for qaPair in response:
|
| 59 |
with st.chat_message("user"):
|
| 60 |
+
st.radio(label=qaPair['question'], options=qaPair["options"], disabled=True,
|
| 61 |
+
index=qaPair['correct_option_index'])
|
| 62 |
|
| 63 |
|
| 64 |
with st.sidebar:
|
|
|
|
| 101 |
index=None,
|
| 102 |
placeholder="Select Category of Question Answer Pairs",
|
| 103 |
)
|
| 104 |
+
numPairs = st.number_input('Number of QA Pairs', min_value=1, max_value=20, step=1, value=2)
|
| 105 |
+
with st.expander("Download your File Now"):
|
| 106 |
+
with st.container(border=True):
|
| 107 |
+
FileName = st.text_input('Enter Your File Name',
|
| 108 |
+
placeholder=' eg. Data, QA-Chap1')
|
| 109 |
+
FileName = FileName + '.json'
|
| 110 |
|
| 111 |
if st.button("Generate", type="primary"):
|
| 112 |
if option == "Long QA Pairs" and len(pages) and option in optionCategory:
|