Spaces:
Running
Running
yukti-kash
commited on
Commit
β’
fc6c542
1
Parent(s):
beab894
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import pandas as pd
|
|
4 |
import traceback
|
5 |
import PyPDF2
|
6 |
import streamlit as st
|
7 |
-
|
8 |
from MCQGenerator import final_chain
|
9 |
|
10 |
from langchain.chat_models import ChatOpenAI
|
@@ -21,68 +21,6 @@ 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 |
|
88 |
st.title("π€ MCQ Generater π¦π")
|
|
|
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
|
|
|
21 |
import PyPDF2
|
22 |
import traceback
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
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')
|
25 |
|
26 |
st.title("π€ MCQ Generater π¦π")
|