mgbam commited on
Commit
473cdbb
·
verified ·
1 Parent(s): e6e5688

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -21
app.py CHANGED
@@ -1,27 +1,40 @@
1
  import gradio as gr
 
2
 
3
- # Define learning paths and corresponding content
4
- learning_paths = {
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 display the selected learning path's content
12
- def show_learning_content(selected_path):
13
  """
14
- Displays content for the selected learning path.
15
  """
16
- return f"You selected: {selected_path}\n\n{learning_paths[selected_path]}"
 
 
 
 
 
 
 
17
 
18
- # Function to simulate feedback or progression
19
- def provide_feedback(selected_path):
20
- return f"Great choice! Let's dive into {selected_path}."
 
 
 
 
 
 
 
 
 
 
21
 
22
  # Gradio interface
23
  with gr.Blocks() as app:
24
- gr.Markdown("## Interactive Learning Platform")
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=list(learning_paths.keys()),
34
  label="Select a Learning Path",
35
  value="Math"
36
  )
37
 
38
  # Buttons for user interaction
39
  with gr.Row():
40
- continue_button = gr.Button("Continue")
41
- feedback_button = gr.Button("Get Feedback")
42
 
43
  # Outputs
44
- learning_output = gr.Textbox(lines=8, interactive=False, label="Learning Content")
 
45
  feedback_output = gr.Textbox(interactive=False, label="Feedback")
46
 
47
  # Link interactions to actions
48
- continue_button.click(fn=show_learning_content, inputs=selected_topic, outputs=learning_output)
49
- feedback_button.click(fn=provide_feedback, inputs=selected_topic, outputs=feedback_output)
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()