yukti-kash commited on
Commit
d4a486b
β€’
1 Parent(s): b159022

Upload 4 files

Browse files
Files changed (4) hide show
  1. Response.json +42 -0
  2. StreamlitAPP.py +116 -0
  3. requirements.txt +7 -0
  4. setup.py +14 -0
Response.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "1": {
3
+ "question": "the mcq question",
4
+ "options": {
5
+ "A": "choice here",
6
+ "B": "choice here",
7
+ "C": "choice here",
8
+ "D": "choice here"
9
+ },
10
+ "correct": "correct choice"
11
+ },
12
+ "2": {
13
+ "question": "the mcq question",
14
+ "options": {
15
+ "A": "choice here",
16
+ "B": "choice here",
17
+ "C": "choice here",
18
+ "D": "choice here"
19
+ },
20
+ "correct": "correct choice"
21
+ },
22
+ "3": {
23
+ "question": "the mcq question",
24
+ "options": {
25
+ "A": "choice here",
26
+ "B": "choice here",
27
+ "C": "choice here",
28
+ "D": "choice here"
29
+ },
30
+ "correct": "correct choice"
31
+ },
32
+ "4": {
33
+ "question": "the mcq question",
34
+ "options": {
35
+ "A": "choice here",
36
+ "B": "choice here",
37
+ "C": "choice here",
38
+ "D": "choice here"
39
+ },
40
+ "correct": "correct choice"
41
+ }
42
+ }
StreamlitAPP.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import pandas as pd
4
+ import traceback
5
+ import PyPDF2
6
+ import streamlit as st
7
+ from src.mcq_gen.util import read_flie, get_table_data
8
+ from src.mcq_gen.MCQGenerater import final_chain
9
+ from dotenv import load_dotenv
10
+ from langchain.chat_models import ChatOpenAI
11
+ from langchain.prompts import PromptTemplate
12
+ from langchain.chains import LLMChain
13
+ from langchain.llms import OpenAI
14
+
15
+ from langchain.callbacks import get_openai_callback
16
+ from langchain.chains import SequentialChain
17
+
18
+
19
+ 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')
20
+
21
+ st.title("πŸ€– MCQ Generater πŸ¦œπŸ”—")
22
+
23
+ st.image('https://miro.medium.com/v2/resize:fit:1400/1*odEY2uy37q-GTb8-u7_j8Q.png')
24
+
25
+
26
+ with open('D:\Project\Response.json','r') as f:
27
+ RESPONSE_JSON = json.load(f)
28
+
29
+
30
+ # taking inputs
31
+
32
+ with st.form("user inputs") :
33
+
34
+ # file upload
35
+
36
+ uploaded_file = st.file_uploader('upload PDF or txt File πŸ‘¨β€πŸš€')
37
+
38
+ # number of mcq
39
+
40
+ num_mcq = st.number_input('no. of mcq 🎯',min_value = 2,max_value = 70)
41
+
42
+ # subject
43
+
44
+ subject = st.text_input('subject πŸ“š',max_chars = 50)
45
+
46
+ level = st.text_input('level of hardness πŸ‘©πŸ»β€πŸ’»', max_chars = 25, placeholder = 'simple')
47
+
48
+ submit = st.form_submit_button("Create")
49
+
50
+ if uploaded_file and submit is not None and subject and level and num_mcq :
51
+
52
+ with st.spinner('loading...😎') :
53
+
54
+ try :
55
+
56
+ # calling the read_file func in utils and it will the uploaded doc text
57
+ text = read_flie(uploaded_file)
58
+ with get_openai_callback() as cb :
59
+
60
+ response = final_chain(
61
+ {
62
+ 'text' : text,
63
+ 'number' : num_mcq,
64
+ 'subject' : subject,
65
+ 'level' : level,
66
+ 'response_json' : json.dumps(RESPONSE_JSON)
67
+ }
68
+ )
69
+ except Exception as e :
70
+ raise Exception('Error coming : Try again later πŸ•΅οΈβ€β™€οΈ')
71
+
72
+ else :
73
+
74
+ # print(response)
75
+ if isinstance(response,dict):
76
+ # make the DataFrame
77
+
78
+ quiz = response.get('quiz',None)
79
+
80
+ if quiz is not None :
81
+
82
+ table_data = get_table_data(quiz)
83
+
84
+ if table_data is not None :
85
+
86
+ df = pd.DataFrame(table_data)
87
+ df.index = df.index+1 # index in the table/df start from 1 and not from 0
88
+ st.table(df)
89
+
90
+
91
+ # displaying review as well
92
+
93
+ st.header('Review πŸ§™πŸ½')
94
+ st.text_area(label = ' ',value=response['complexity'])
95
+
96
+ else :
97
+ st.error("Sorry : There is an Error in Table Data πŸ•΅οΈβ€β™€οΈ")
98
+
99
+ else :
100
+
101
+ st.error("Sorry : Error in Quiz πŸ•΅οΈβ€β™€οΈ")
102
+
103
+ else :
104
+
105
+ st.write(response)
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ openai
2
+ langchain
3
+ python-dotenv
4
+ PyPDF2
5
+ streamlit
6
+
7
+ -e .
setup.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from setuptools import setup,find_packages
2
+
3
+ # find_packages - automatically detect the local packages
4
+
5
+ setup(
6
+
7
+ name = 'mecq_gen',
8
+ version='0.0.1',
9
+ description='Creating the projcet : MCQ Generater',
10
+ author='Yukti Kashyap',
11
+ author_email='kashyapyukti12@gmail.com',
12
+ install_requires=['openai','langchain','streamlit','python-dotenv','PyPDF2'],
13
+ packages=find_packages()
14
+ )