Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,3 @@
|
|
| 1 |
-
# Install dependencies (if needed)
|
| 2 |
-
# !pip install gradio pandas scikit-learn
|
| 3 |
-
|
| 4 |
import pandas as pd
|
| 5 |
import gradio as gr
|
| 6 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
|
@@ -9,16 +6,15 @@ from sklearn.metrics.pairwise import cosine_similarity
|
|
| 9 |
# Load dataset
|
| 10 |
df = pd.read_csv("mcq_dataset.csv")
|
| 11 |
|
| 12 |
-
#
|
| 13 |
df['domain'] = df['domain'].astype(str).str.strip().str.lower()
|
| 14 |
df['subdomain'] = df['subdomain'].astype(str).str.strip()
|
| 15 |
|
| 16 |
-
# Function to
|
| 17 |
def get_top_mcqs(user_input, domain, subdomain, top_n=10):
|
| 18 |
if not domain or not subdomain:
|
| 19 |
return pd.DataFrame()
|
| 20 |
|
| 21 |
-
# Normalize input for comparison
|
| 22 |
domain = domain.strip().lower()
|
| 23 |
subdomain = subdomain.strip()
|
| 24 |
|
|
@@ -41,7 +37,7 @@ def get_top_mcqs(user_input, domain, subdomain, top_n=10):
|
|
| 41 |
|
| 42 |
return top_questions.reset_index(drop=True)
|
| 43 |
|
| 44 |
-
#
|
| 45 |
def run_quiz(domain, subdomain, keyword_input):
|
| 46 |
mcq_df = get_top_mcqs(keyword_input, domain, subdomain)
|
| 47 |
|
|
@@ -59,26 +55,31 @@ def run_quiz(domain, subdomain, keyword_input):
|
|
| 59 |
|
| 60 |
return quiz_output
|
| 61 |
|
| 62 |
-
#
|
| 63 |
def update_subdomains(domain):
|
| 64 |
if not domain:
|
| 65 |
return gr.Dropdown.update(choices=[], value=None)
|
| 66 |
|
| 67 |
domain = domain.strip().lower()
|
| 68 |
subdomains = df[df["domain"] == domain]["subdomain"].dropna().unique().tolist()
|
| 69 |
-
|
| 70 |
if not subdomains:
|
| 71 |
subdomains = ["No Subdomains Available"]
|
| 72 |
|
| 73 |
return gr.Dropdown.update(choices=sorted(subdomains), value=subdomains[0])
|
| 74 |
|
| 75 |
-
# Gradio
|
| 76 |
with gr.Blocks() as demo:
|
| 77 |
gr.Markdown("## 🧠 Domain-Based MCQ Quiz System")
|
| 78 |
|
| 79 |
-
with gr.
|
| 80 |
-
domain_dropdown = gr.Dropdown(
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
domain_dropdown.change(fn=update_subdomains, inputs=domain_dropdown, outputs=subdomain_dropdown)
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import gradio as gr
|
| 3 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
|
|
|
| 6 |
# Load dataset
|
| 7 |
df = pd.read_csv("mcq_dataset.csv")
|
| 8 |
|
| 9 |
+
# Normalize domain and subdomain values
|
| 10 |
df['domain'] = df['domain'].astype(str).str.strip().str.lower()
|
| 11 |
df['subdomain'] = df['subdomain'].astype(str).str.strip()
|
| 12 |
|
| 13 |
+
# Function to fetch top MCQs
|
| 14 |
def get_top_mcqs(user_input, domain, subdomain, top_n=10):
|
| 15 |
if not domain or not subdomain:
|
| 16 |
return pd.DataFrame()
|
| 17 |
|
|
|
|
| 18 |
domain = domain.strip().lower()
|
| 19 |
subdomain = subdomain.strip()
|
| 20 |
|
|
|
|
| 37 |
|
| 38 |
return top_questions.reset_index(drop=True)
|
| 39 |
|
| 40 |
+
# Function to format quiz output
|
| 41 |
def run_quiz(domain, subdomain, keyword_input):
|
| 42 |
mcq_df = get_top_mcqs(keyword_input, domain, subdomain)
|
| 43 |
|
|
|
|
| 55 |
|
| 56 |
return quiz_output
|
| 57 |
|
| 58 |
+
# Dynamic subdomain update
|
| 59 |
def update_subdomains(domain):
|
| 60 |
if not domain:
|
| 61 |
return gr.Dropdown.update(choices=[], value=None)
|
| 62 |
|
| 63 |
domain = domain.strip().lower()
|
| 64 |
subdomains = df[df["domain"] == domain]["subdomain"].dropna().unique().tolist()
|
|
|
|
| 65 |
if not subdomains:
|
| 66 |
subdomains = ["No Subdomains Available"]
|
| 67 |
|
| 68 |
return gr.Dropdown.update(choices=sorted(subdomains), value=subdomains[0])
|
| 69 |
|
| 70 |
+
# Gradio Interface
|
| 71 |
with gr.Blocks() as demo:
|
| 72 |
gr.Markdown("## 🧠 Domain-Based MCQ Quiz System")
|
| 73 |
|
| 74 |
+
with gr.Column():
|
| 75 |
+
domain_dropdown = gr.Dropdown(
|
| 76 |
+
label="Select Domain",
|
| 77 |
+
choices=sorted(df['domain'].unique().tolist())
|
| 78 |
+
)
|
| 79 |
+
subdomain_dropdown = gr.Dropdown(
|
| 80 |
+
label="Select Subdomain",
|
| 81 |
+
filterable=True # 👈 Enables searching subdomains
|
| 82 |
+
)
|
| 83 |
|
| 84 |
domain_dropdown.change(fn=update_subdomains, inputs=domain_dropdown, outputs=subdomain_dropdown)
|
| 85 |
|