Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,40 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
-
"Math": "Welcome to the Math path! Solve problems and explore concepts like algebra, calculus, and geometry.",
|
6 |
-
"Science & Engineering": "Dive into physics, chemistry, and engineering concepts with interactive examples.",
|
7 |
-
"Computer Science & Programming": "Learn programming, algorithms, and computer science fundamentals.",
|
8 |
-
"Data Science & Data Analysis": "Master data manipulation, visualization, and analysis techniques."
|
9 |
-
}
|
10 |
|
11 |
-
# Function to
|
12 |
-
def
|
13 |
"""
|
14 |
-
|
15 |
"""
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
# Function to
|
19 |
-
def
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
# Gradio interface
|
23 |
with gr.Blocks() as app:
|
24 |
-
gr.Markdown("##
|
25 |
gr.Markdown("Choose a topic to start learning:")
|
26 |
|
27 |
# Progress bar at the top (HTML-based)
|
@@ -30,23 +43,24 @@ with gr.Blocks() as app:
|
|
30 |
|
31 |
# Options for learning paths
|
32 |
selected_topic = gr.Radio(
|
33 |
-
choices=
|
34 |
label="Select a Learning Path",
|
35 |
value="Math"
|
36 |
)
|
37 |
|
38 |
# Buttons for user interaction
|
39 |
with gr.Row():
|
40 |
-
|
41 |
-
|
42 |
|
43 |
# Outputs
|
44 |
-
|
|
|
45 |
feedback_output = gr.Textbox(interactive=False, label="Feedback")
|
46 |
|
47 |
# Link interactions to actions
|
48 |
-
|
49 |
-
|
50 |
|
51 |
# Launch the app
|
52 |
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
# Initialize Hugging Face Inference Client
|
5 |
+
client = InferenceClient()
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
# Function to use a model for generating content dynamically
|
8 |
+
def generate_content(selected_path):
|
9 |
"""
|
10 |
+
Generates dynamic content based on the selected learning path using an NLP model.
|
11 |
"""
|
12 |
+
prompt = f"Create a short lesson or problem for the topic: {selected_path}."
|
13 |
+
response = client.text_generation(
|
14 |
+
model="gpt2", # Replace with a more suitable Hugging Face model for educational tasks
|
15 |
+
inputs=prompt,
|
16 |
+
max_new_tokens=150,
|
17 |
+
temperature=0.7
|
18 |
+
)
|
19 |
+
return response["generated_text"]
|
20 |
|
21 |
+
# Function to evaluate user input (for example, math problem answers)
|
22 |
+
def evaluate_answer(user_input, selected_path):
|
23 |
+
"""
|
24 |
+
Evaluates user input using the model and provides feedback.
|
25 |
+
"""
|
26 |
+
prompt = f"Evaluate the following response for {selected_path}:\n\nUser Answer: {user_input}\nProvide feedback."
|
27 |
+
response = client.text_generation(
|
28 |
+
model="gpt2", # Replace with a more appropriate evaluation model
|
29 |
+
inputs=prompt,
|
30 |
+
max_new_tokens=100,
|
31 |
+
temperature=0.5
|
32 |
+
)
|
33 |
+
return response["generated_text"]
|
34 |
|
35 |
# Gradio interface
|
36 |
with gr.Blocks() as app:
|
37 |
+
gr.Markdown("## AI-Powered Learning Platform")
|
38 |
gr.Markdown("Choose a topic to start learning:")
|
39 |
|
40 |
# Progress bar at the top (HTML-based)
|
|
|
43 |
|
44 |
# Options for learning paths
|
45 |
selected_topic = gr.Radio(
|
46 |
+
choices=["Math", "Science & Engineering", "Computer Science & Programming", "Data Science & Data Analysis"],
|
47 |
label="Select a Learning Path",
|
48 |
value="Math"
|
49 |
)
|
50 |
|
51 |
# Buttons for user interaction
|
52 |
with gr.Row():
|
53 |
+
generate_button = gr.Button("Generate Content")
|
54 |
+
submit_answer_button = gr.Button("Submit Answer")
|
55 |
|
56 |
# Outputs
|
57 |
+
content_output = gr.Textbox(lines=8, interactive=False, label="Generated Content")
|
58 |
+
answer_input = gr.Textbox(lines=2, label="Your Answer")
|
59 |
feedback_output = gr.Textbox(interactive=False, label="Feedback")
|
60 |
|
61 |
# Link interactions to actions
|
62 |
+
generate_button.click(fn=generate_content, inputs=selected_topic, outputs=content_output)
|
63 |
+
submit_answer_button.click(fn=evaluate_answer, inputs=[answer_input, selected_topic], outputs=feedback_output)
|
64 |
|
65 |
# Launch the app
|
66 |
app.launch()
|