add MCQs api
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import warnings
|
| 3 |
from typing import List
|
|
|
|
| 4 |
from pdfitdown.pdfconversion import convert_to_pdf, convert_markdown_to_pdf
|
| 5 |
|
| 6 |
from base_utils import (
|
|
@@ -121,6 +122,79 @@ def convert(file: str) -> str:
|
|
| 121 |
return pdfs
|
| 122 |
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
pdf_converter = gr.Interface(
|
| 125 |
fn=convert,
|
| 126 |
inputs=gr.File(label="Upload your file"),
|
|
@@ -140,6 +214,7 @@ demo = gr.TabbedInterface(
|
|
| 140 |
pptx_to_text,
|
| 141 |
url_parser,
|
| 142 |
str_to_json,
|
|
|
|
| 143 |
pdf_converter,
|
| 144 |
],
|
| 145 |
[
|
|
@@ -151,6 +226,7 @@ demo = gr.TabbedInterface(
|
|
| 151 |
"Extract PPTX Text",
|
| 152 |
"Extract text from URL",
|
| 153 |
"Extract Json",
|
|
|
|
| 154 |
"Convert to PDF",
|
| 155 |
],
|
| 156 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import warnings
|
| 3 |
from typing import List
|
| 4 |
+
import json
|
| 5 |
from pdfitdown.pdfconversion import convert_to_pdf, convert_markdown_to_pdf
|
| 6 |
|
| 7 |
from base_utils import (
|
|
|
|
| 122 |
return pdfs
|
| 123 |
|
| 124 |
|
| 125 |
+
def parse_MCQs(mcq_string: str) -> List[List[str]]:
|
| 126 |
+
mcq_string = "[" + mcq_string.split("[", 1)[1]
|
| 127 |
+
json_data = mcq_string.rsplit("]", 1)[0] + "]"
|
| 128 |
+
json_data = json.loads(json_data)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
mcqs_to_json = gr.Interface(
|
| 132 |
+
parse_MCQs,
|
| 133 |
+
gr.Textbox(),
|
| 134 |
+
gr.JSON(),
|
| 135 |
+
api_name="mcqs_to_json",
|
| 136 |
+
examples=[
|
| 137 |
+
[
|
| 138 |
+
"""```json
|
| 139 |
+
[
|
| 140 |
+
{
|
| 141 |
+
"question": "Which of the following best describes the nature of business?",
|
| 142 |
+
"options": {
|
| 143 |
+
"A": "It is primarily a non-economic activity",
|
| 144 |
+
"B": "It involves personal consumption of goods",
|
| 145 |
+
"C": "It includes regular and continuous transactions for profit",
|
| 146 |
+
"D": "It excludes exchange of goods and services"
|
| 147 |
+
},
|
| 148 |
+
"answer": "C"
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"question": "According to the document, what is a primary objective of business under economic objectives?",
|
| 152 |
+
"options": {
|
| 153 |
+
"A": "Employee welfare",
|
| 154 |
+
"B": "Profit earning",
|
| 155 |
+
"C": "Creating entertainment content",
|
| 156 |
+
"D": "Reducing government involvement"
|
| 157 |
+
},
|
| 158 |
+
"answer": "B"
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"question": "Which of the following is a component of commerce?",
|
| 162 |
+
"options": {
|
| 163 |
+
"A": "Mining",
|
| 164 |
+
"B": "Manufacturing",
|
| 165 |
+
"C": "Warehousing",
|
| 166 |
+
"D": "Farming"
|
| 167 |
+
},
|
| 168 |
+
"answer": "C"
|
| 169 |
+
},
|
| 170 |
+
{
|
| 171 |
+
"question": "What is an example of a synthetic manufacturing industry?",
|
| 172 |
+
"options": {
|
| 173 |
+
"A": "Oil refining",
|
| 174 |
+
"B": "Textile processing",
|
| 175 |
+
"C": "Soap production",
|
| 176 |
+
"D": "Watch assembly"
|
| 177 |
+
},
|
| 178 |
+
"answer": "C"
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"question": "Which aid to trade helps in overcoming the hindrance of knowledge in commerce?",
|
| 182 |
+
"options": {
|
| 183 |
+
"A": "Banking",
|
| 184 |
+
"B": "Insurance",
|
| 185 |
+
"C": "Advertising",
|
| 186 |
+
"D": "Warehousing"
|
| 187 |
+
},
|
| 188 |
+
"answer": "C"
|
| 189 |
+
}
|
| 190 |
+
]
|
| 191 |
+
```
|
| 192 |
+
"""
|
| 193 |
+
]
|
| 194 |
+
],
|
| 195 |
+
cache_examples=False,
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
pdf_converter = gr.Interface(
|
| 199 |
fn=convert,
|
| 200 |
inputs=gr.File(label="Upload your file"),
|
|
|
|
| 214 |
pptx_to_text,
|
| 215 |
url_parser,
|
| 216 |
str_to_json,
|
| 217 |
+
mcqs_to_json,
|
| 218 |
pdf_converter,
|
| 219 |
],
|
| 220 |
[
|
|
|
|
| 226 |
"Extract PPTX Text",
|
| 227 |
"Extract text from URL",
|
| 228 |
"Extract Json",
|
| 229 |
+
"Parse MCQs",
|
| 230 |
"Convert to PDF",
|
| 231 |
],
|
| 232 |
)
|