cryogenic22 commited on
Commit
a29f061
·
verified ·
1 Parent(s): 6f53ebf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from learning_platform import LearningPlatform
4
+ import asyncio
5
+ import nest_asyncio
6
+ nest_asyncio.apply()
7
+
8
+ # Initialize the platform with environment variable
9
+ platform = LearningPlatform(os.environ.get('OPENAI_API_KEY'))
10
+
11
+ async def create_course(topic, difficulty):
12
+ try:
13
+ learning_path = await platform.create_course(topic, difficulty)
14
+
15
+ # Format the output
16
+ output = f"Course: {learning_path.topic}\n"
17
+ output += f"Difficulty: {learning_path.difficulty_level}\n\n"
18
+
19
+ for i, module in enumerate(learning_path.modules, 1):
20
+ output += f"Module {i}: {module.title}\n"
21
+ output += f"Content:\n{module.content}\n\n"
22
+ output += "Quiz Questions:\n"
23
+ for j, question in enumerate(module.quiz_questions, 1):
24
+ output += f"Q{j}: {question['question']}\n"
25
+ output += f"Options: {', '.join(question['options'])}\n"
26
+ output += f"Answer: {question['correct_answer']}\n\n"
27
+
28
+ return output
29
+ except Exception as e:
30
+ return f"Error generating course: {str(e)}"
31
+
32
+ # Create the Gradio interface
33
+ demo = gr.Interface(
34
+ fn=create_course,
35
+ inputs=[
36
+ gr.Textbox(label="Enter topic", placeholder="e.g., Python Programming"),
37
+ gr.Dropdown(
38
+ choices=["beginner", "intermediate", "advanced"],
39
+ label="Select difficulty",
40
+ value="beginner"
41
+ )
42
+ ],
43
+ outputs="text",
44
+ title="AI Learning Platform",
45
+ description="Generate personalized learning paths for any topic",
46
+ examples=[
47
+ ["Python Programming", "beginner"],
48
+ ["Machine Learning", "intermediate"],
49
+ ["Web Development", "beginner"]
50
+ ]
51
+ )
52
+
53
+ if __name__ == "__main__":
54
+ demo.launch()