Hidayatmahar commited on
Commit
5745244
·
verified ·
1 Parent(s): 30b89e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -87,48 +87,64 @@ questions = [
87
  "answer": "ڪڻڪ"}
88
  ]
89
 
 
90
  def evaluate(name, *answers):
 
 
 
 
 
 
91
  score = 0
92
-
93
  for i, answer in enumerate(answers):
94
  if answer == questions[i]["answer"]:
95
  score += 1
96
 
97
  percentage = (score / len(questions)) * 100
98
 
 
 
 
 
 
 
 
 
 
 
99
  result = f"""
100
  📘 Student Name: {name}
101
 
102
  ✅ Correct Answers: {score} / {len(questions)}
103
  📊 Percentage: {percentage:.2f}%
 
104
 
105
- 👨‍💻 Developer: {DEVELOPER}
106
  🏫 School: {SCHOOL}
107
  """
108
  return result
109
 
 
110
  with gr.Blocks() as app:
111
-
112
  gr.Markdown(f"""
113
  # 📘 Class 5 Sindhi Test System
114
 
115
  🏫 {SCHOOL}
116
- 👨‍💻 Developed by: {DEVELOPER}
117
 
118
  ---
119
- Please answer all questions and click Submit.
120
- """)
121
 
122
  name = gr.Textbox(label="Enter Student Name")
123
 
124
  answer_inputs = []
125
-
126
  for q in questions:
127
  radio = gr.Radio(q["options"], label=q["question"])
128
  answer_inputs.append(radio)
129
 
130
  submit_btn = gr.Button("Submit Test")
131
- output = gr.Textbox(label="Result")
132
 
133
  submit_btn.click(
134
  evaluate,
 
87
  "answer": "ڪڻڪ"}
88
  ]
89
 
90
+ # Function to evaluate test
91
  def evaluate(name, *answers):
92
+ if not name.strip():
93
+ return "⚠️ مهرباني ڪري پنهنجو نالو داخل ڪريو."
94
+
95
+ if None in answers:
96
+ return "⚠️ مهرباني ڪري سڀ سوالن جا جواب ڏيو."
97
+
98
  score = 0
 
99
  for i, answer in enumerate(answers):
100
  if answer == questions[i]["answer"]:
101
  score += 1
102
 
103
  percentage = (score / len(questions)) * 100
104
 
105
+ # Optional grade
106
+ if percentage >= 80:
107
+ grade = "A+ 🌟"
108
+ elif percentage >= 60:
109
+ grade = "B 👍"
110
+ elif percentage >= 40:
111
+ grade = "C 🙂"
112
+ else:
113
+ grade = "Needs Improvement ❗"
114
+
115
  result = f"""
116
  📘 Student Name: {name}
117
 
118
  ✅ Correct Answers: {score} / {len(questions)}
119
  📊 Percentage: {percentage:.2f}%
120
+ 🎖 Grade: {grade}
121
 
122
+ 👨‍💻 Developer: <span style="color:blue;"><b>{DEVELOPER}</b></span>
123
  🏫 School: {SCHOOL}
124
  """
125
  return result
126
 
127
+ # Gradio UI
128
  with gr.Blocks() as app:
 
129
  gr.Markdown(f"""
130
  # 📘 Class 5 Sindhi Test System
131
 
132
  🏫 {SCHOOL}
133
+ 👨‍💻 Developed by: <span style="color:blue;"><b>{DEVELOPER}</b></span>
134
 
135
  ---
136
+ مهرباني ڪري سڀ سوال ڀريو ۽ Submit تي ڪلڪ ڪريو.
137
+ """, elem_id="header")
138
 
139
  name = gr.Textbox(label="Enter Student Name")
140
 
141
  answer_inputs = []
 
142
  for q in questions:
143
  radio = gr.Radio(q["options"], label=q["question"])
144
  answer_inputs.append(radio)
145
 
146
  submit_btn = gr.Button("Submit Test")
147
+ output = gr.Textbox(label="Result", lines=15)
148
 
149
  submit_btn.click(
150
  evaluate,