Spaces:
Sleeping
Sleeping
Commit
·
a0b3a97
1
Parent(s):
ee7b846
test
Browse files- Gradio_UI.py +2 -0
- QCMTest.py +62 -0
- tools/QCMTool.py +2 -0
Gradio_UI.py
CHANGED
@@ -292,6 +292,7 @@ class GradioUI:
|
|
292 |
# Description
|
293 |
examples=examples, # Example inputs
|
294 |
)
|
|
|
295 |
# If an upload folder is provided, enable the upload feature
|
296 |
if self.file_upload_folder is not None:
|
297 |
upload_file = gr.File(label="Upload a file")
|
@@ -308,6 +309,7 @@ class GradioUI:
|
|
308 |
[stored_messages, text_input],
|
309 |
).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])
|
310 |
|
|
|
311 |
demo.launch(debug=True, share=True, **kwargs)
|
312 |
|
313 |
|
|
|
292 |
# Description
|
293 |
examples=examples, # Example inputs
|
294 |
)
|
295 |
+
chatbot.example_select(self.log_user_message, [chatbot], [chatbot]).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])
|
296 |
# If an upload folder is provided, enable the upload feature
|
297 |
if self.file_upload_folder is not None:
|
298 |
upload_file = gr.File(label="Upload a file")
|
|
|
309 |
[stored_messages, text_input],
|
310 |
).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])
|
311 |
|
312 |
+
|
313 |
demo.launch(debug=True, share=True, **kwargs)
|
314 |
|
315 |
|
QCMTest.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import gradio as gr
|
3 |
+
from smolagents import tool, CodeAgent, HfApiModel
|
4 |
+
|
5 |
+
# Sample questions and answers
|
6 |
+
questions = [
|
7 |
+
{
|
8 |
+
"question": "What is the capital of France?",
|
9 |
+
"choices": ["Paris", "London", "Berlin", "Madrid"],
|
10 |
+
"answer": "Paris"
|
11 |
+
},
|
12 |
+
{
|
13 |
+
"question": "What is 2 + 2?",
|
14 |
+
"choices": ["3", "4", "5", "6"],
|
15 |
+
"answer": "4"
|
16 |
+
}
|
17 |
+
]
|
18 |
+
|
19 |
+
|
20 |
+
@tool
|
21 |
+
def qcm_test(user_answer: str) -> str:
|
22 |
+
"""
|
23 |
+
This tool selects a random question from a predefined list and asks the user to pick an option.
|
24 |
+
It returns whether the user's answer is correct or not.
|
25 |
+
|
26 |
+
Args:
|
27 |
+
user_answer: The user's selected answer.
|
28 |
+
"""
|
29 |
+
# Select a random question
|
30 |
+
question = random.choice(questions)
|
31 |
+
|
32 |
+
# Check if the user's answer is correct
|
33 |
+
if user_answer.strip() == question['answer']:
|
34 |
+
return "Correct!"
|
35 |
+
else:
|
36 |
+
return f"Incorrect. The correct answer is {question['answer']}."
|
37 |
+
|
38 |
+
|
39 |
+
# Initialize the agent with the QCM test tool
|
40 |
+
model = HfApiModel()
|
41 |
+
agent = CodeAgent(tools=[qcm_test], model=model)
|
42 |
+
|
43 |
+
|
44 |
+
# Define the Gradio interface
|
45 |
+
def gradio_qcm_test():
|
46 |
+
question = random.choice(questions)
|
47 |
+
user_answer = gr.Dropdown(label="Select your answer", choices=question['choices'])
|
48 |
+
result = qcm_test(user_answer)
|
49 |
+
return question['question'], result
|
50 |
+
|
51 |
+
|
52 |
+
# Create the Gradio interface
|
53 |
+
iface = gr.Interface(
|
54 |
+
fn=gradio_qcm_test,
|
55 |
+
inputs=None,
|
56 |
+
outputs=[gr.Textbox(label="Question"), gr.Textbox(label="Result")],
|
57 |
+
title="QCM Test",
|
58 |
+
description="Select an answer to the question and see if you are correct."
|
59 |
+
)
|
60 |
+
|
61 |
+
# Launch the Gradio interface
|
62 |
+
iface.launch()
|
tools/QCMTool.py
CHANGED
@@ -109,6 +109,8 @@ class QCMTool(Tool):
|
|
109 |
if __name__ == "__main__":
|
110 |
# Initialize the QCM tool
|
111 |
qcm_tool = QCMTool(json_file="../info/questions.json")
|
|
|
|
|
112 |
|
113 |
# Simulate a user answering 'A'
|
114 |
try:
|
|
|
109 |
if __name__ == "__main__":
|
110 |
# Initialize the QCM tool
|
111 |
qcm_tool = QCMTool(json_file="../info/questions.json")
|
112 |
+
question=qcm_tool._pick_random_question()
|
113 |
+
print(question)
|
114 |
|
115 |
# Simulate a user answering 'A'
|
116 |
try:
|