Spaces:
Running
Running
File size: 3,495 Bytes
d4a486b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
import os
import json
import pandas as pd
import traceback
import PyPDF2
import streamlit as st
from src.mcq_gen.util import read_flie, get_table_data
from src.mcq_gen.MCQGenerater import final_chain
from dotenv import load_dotenv
from langchain.chat_models import ChatOpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.llms import OpenAI
from langchain.callbacks import get_openai_callback
from langchain.chains import SequentialChain
st.set_page_config(page_title = "MCQ Generater", page_icon='https://archive.org/download/github.com-langchain-ai-langchain_-_2023-09-20_11-56-54/cover.jpg')
st.title("π€ MCQ Generater π¦π")
st.image('https://miro.medium.com/v2/resize:fit:1400/1*odEY2uy37q-GTb8-u7_j8Q.png')
with open('D:\Project\Response.json','r') as f:
RESPONSE_JSON = json.load(f)
# taking inputs
with st.form("user inputs") :
# file upload
uploaded_file = st.file_uploader('upload PDF or txt File π¨βπ')
# number of mcq
num_mcq = st.number_input('no. of mcq π―',min_value = 2,max_value = 70)
# subject
subject = st.text_input('subject π',max_chars = 50)
level = st.text_input('level of hardness π©π»βπ»', max_chars = 25, placeholder = 'simple')
submit = st.form_submit_button("Create")
if uploaded_file and submit is not None and subject and level and num_mcq :
with st.spinner('loading...π') :
try :
# calling the read_file func in utils and it will the uploaded doc text
text = read_flie(uploaded_file)
with get_openai_callback() as cb :
response = final_chain(
{
'text' : text,
'number' : num_mcq,
'subject' : subject,
'level' : level,
'response_json' : json.dumps(RESPONSE_JSON)
}
)
except Exception as e :
raise Exception('Error coming : Try again later π΅οΈββοΈ')
else :
# print(response)
if isinstance(response,dict):
# make the DataFrame
quiz = response.get('quiz',None)
if quiz is not None :
table_data = get_table_data(quiz)
if table_data is not None :
df = pd.DataFrame(table_data)
df.index = df.index+1 # index in the table/df start from 1 and not from 0
st.table(df)
# displaying review as well
st.header('Review π§π½')
st.text_area(label = ' ',value=response['complexity'])
else :
st.error("Sorry : There is an Error in Table Data π΅οΈββοΈ")
else :
st.error("Sorry : Error in Quiz π΅οΈββοΈ")
else :
st.write(response)
|