yukti-kash commited on
Commit
beab894
1 Parent(s): bf7eaec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -1
app.py CHANGED
@@ -4,7 +4,7 @@ import pandas as pd
4
  import traceback
5
  import PyPDF2
6
  import streamlit as st
7
- from util import read_flie, get_table_data
8
  from MCQGenerator import final_chain
9
 
10
  from langchain.chat_models import ChatOpenAI
@@ -15,6 +15,73 @@ from langchain.llms import OpenAI
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
 
@@ -27,6 +94,7 @@ with open('Response.json','r') as f:
27
  RESPONSE_JSON = json.load(f)
28
 
29
 
 
30
  # taking inputs
31
 
32
  with st.form("user inputs") :
 
4
  import traceback
5
  import PyPDF2
6
  import streamlit as st
7
+ # from util import read_flie, get_table_data
8
  from MCQGenerator import final_chain
9
 
10
  from langchain.chat_models import ChatOpenAI
 
15
  from langchain.callbacks import get_openai_callback
16
  from langchain.chains import SequentialChain
17
 
18
+ import os
19
+ import json
20
+ import pandas as pd
21
+ import PyPDF2
22
+ import traceback
23
+
24
+
25
+ def read_flie(file):
26
+
27
+ if file.name.endswith('.pdf'):
28
+ try :
29
+
30
+ pdf_content = PyPDF2.PdfFileReader(file)
31
+
32
+ text = ''
33
+
34
+ for page in pdf_content.pages:
35
+ text+=page
36
+
37
+ return text
38
+
39
+ except Exception as e :
40
+ raise Exception( 'error in reading the file >> Please try reuploading')
41
+
42
+ elif file.name.endswith('.txt'):
43
+
44
+ return file.read().decode('utf-8')
45
+
46
+ else :
47
+
48
+ raise Exception(
49
+
50
+ 'Not File desired format : only PDF and txt files are supported '
51
+ )
52
+
53
+
54
+ def get_table_data(quiz_str):
55
+
56
+ try :
57
+
58
+ quiz_dict = json.loads(quiz_str)
59
+
60
+ table = []
61
+
62
+ for key,value in quiz_dict.items():
63
+
64
+ print(key," | ",value)
65
+
66
+ ques = value['question']
67
+ options = ' | '.join(
68
+ [
69
+ f"{option} : {options}"
70
+ for option, options in value['options'].items()
71
+
72
+ ]
73
+ )
74
+ correct = value['correct']
75
+ table.append({'ques':ques,'options' : options, 'correct' : correct})
76
+
77
+ return table
78
+
79
+ except Exception as e :
80
+
81
+ # traceback.print(e)
82
+
83
+ return False
84
+
85
 
86
  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')
87
 
 
94
  RESPONSE_JSON = json.load(f)
95
 
96
 
97
+
98
  # taking inputs
99
 
100
  with st.form("user inputs") :