ldrissi commited on
Commit
2c37bf7
·
1 Parent(s): 17159df

finish the idea of micro learning part 5

Browse files
Files changed (3) hide show
  1. README.md +16 -17
  2. app.py +31 -10
  3. requirements.txt +3 -2
README.md CHANGED
@@ -7,24 +7,23 @@ sdk: gradio
7
  sdk_version: 5.29.0
8
  app_file: app.py
9
  pinned: false
10
- short_description: micro learning
11
  ---
12
 
 
13
 
14
- /micro_learning_platform
15
- /api
16
- main.py # FastAPI/Flask entry point
17
- models.py # Data models
18
- routes.py # API endpoints
19
- /ai
20
- huggingface.py # Hugging Face integration
21
- agents.py # Your MCP agents
22
- /data
23
- content.py # Content management
24
- users.py # User management
25
- /frontend
26
- templates/ # Simple templates if needed
27
- static/ # CSS/JS assets
28
- app.py # Main application entry
29
 
30
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
7
  sdk_version: 5.29.0
8
  app_file: app.py
9
  pinned: false
10
+ short_description: A microlearning platform demo
11
  ---
12
 
13
+ # Micro Learning Platform
14
 
15
+ This is a demonstration of a microlearning platform that uses AI to help users learn concepts in small, digestible chunks.
16
+
17
+ ## Features
18
+ - Browse microlearning content
19
+ - Get summaries of learning modules
20
+ - Ask questions about content
 
 
 
 
 
 
 
 
 
21
 
22
+ ## Project Structure
23
+ ```python
24
+ /micro_learning_platform
25
+ /api # Future API endpoints
26
+ /ai # Future AI integration
27
+ /data # Future data management
28
+ /frontend # Future web interface
29
+ app.py # Main application entry
app.py CHANGED
@@ -1,31 +1,52 @@
1
- # Minimal app.py for Hugging Face Spaces
2
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
3
 
4
  # Mock data for demonstration
5
  sample_content = {
6
  "module1": {
7
  "title": "Introduction to AI",
8
- "text": "Artificial Intelligence (AI) is the simulation of human intelligence processes by machines, especially computer systems. These processes include learning, reasoning, and self-correction."
9
  },
10
  "module2": {
11
  "title": "Python Basics",
12
- "text": "Python is a high-level, interpreted programming language known for its readability and simplicity. It is widely used in data science, machine learning, and web development."
13
  },
14
  "module3": {
15
  "title": "Microlearning Concepts",
16
- "text": "Microlearning is an educational strategy that focuses on delivering content in small, specific bursts. Each learning unit typically addresses one learning objective and takes 3-5 minutes to complete."
17
  }
18
  }
19
 
20
- # Mock functions
21
  def get_summary(content_id):
22
- """Generate a mock summary for demonstration"""
23
  if content_id not in sample_content:
24
  return "Content not found"
25
 
26
  text = sample_content[content_id]["text"]
27
- # Simple mock summary - just return the first sentence
28
- return text.split('.')[0] + "."
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  def answer_question(content_id, question):
31
  """Generate a mock answer for demonstration"""
@@ -34,7 +55,7 @@ def answer_question(content_id, question):
34
 
35
  text = sample_content[content_id]["text"]
36
 
37
- # Very simple mock QA system - check if key words from question appear in text
38
  question_words = set(question.lower().split())
39
  important_words = [word for word in question_words if len(word) > 3 and word not in ["what", "when", "where", "which", "how", "this", "that", "with", "from", "have", "about"]]
40
 
@@ -83,7 +104,7 @@ with demo:
83
 
84
  with gr.Tab("Summarize"):
85
  summary_button = gr.Button("Generate Summary")
86
- summary_output = gr.Textbox(label="Summary", lines=2)
87
 
88
  summary_button.click(
89
  fn=get_summary,
 
1
+ # Improved app.py with real summarization using Hugging Face model
2
  import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ # Initialize the summarization model
6
+ try:
7
+ # Use a smaller, faster model for summarization
8
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn", device=-1) # Using CPU
9
+ print("Summarization model loaded successfully!")
10
+ except Exception as e:
11
+ print(f"Error loading summarization model: {e}")
12
+ summarizer = None
13
 
14
  # Mock data for demonstration
15
  sample_content = {
16
  "module1": {
17
  "title": "Introduction to AI",
18
+ "text": "Artificial Intelligence (AI) is the simulation of human intelligence processes by machines, especially computer systems. These processes include learning, reasoning, and self-correction. AI can be categorized as either weak or strong. Weak AI is designed to complete a narrow task, like facial recognition. Strong AI can perform any intellectual task that a human being can do."
19
  },
20
  "module2": {
21
  "title": "Python Basics",
22
+ "text": "Python is a high-level, interpreted programming language known for its readability and simplicity. It is widely used in data science, machine learning, and web development. Python's syntax allows programmers to express concepts in fewer lines of code than languages like C++ or Java. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming."
23
  },
24
  "module3": {
25
  "title": "Microlearning Concepts",
26
+ "text": "Microlearning is an educational strategy that focuses on delivering content in small, specific bursts. Each learning unit typically addresses one learning objective and takes 3-5 minutes to complete. This approach is particularly effective for modern learners with limited time and attention spans. It often incorporates multimedia elements and is optimized for mobile devices, allowing learning to happen anywhere."
27
  }
28
  }
29
 
30
+ # Function to generate real summaries using Hugging Face model
31
  def get_summary(content_id):
32
+ """Generate a summary using a HuggingFace model"""
33
  if content_id not in sample_content:
34
  return "Content not found"
35
 
36
  text = sample_content[content_id]["text"]
37
+
38
+ if summarizer is None:
39
+ # Fallback to simple summary if model failed to load
40
+ return text.split('.')[0] + "."
41
+
42
+ try:
43
+ # Generate summary using the model
44
+ summary = summarizer(text, max_length=60, min_length=20, do_sample=False)
45
+ return summary[0]['summary_text']
46
+ except Exception as e:
47
+ print(f"Error generating summary: {e}")
48
+ # Fallback to simple summary if model fails
49
+ return f"Error generating summary. Fallback: {text.split('.')[0]}."
50
 
51
  def answer_question(content_id, question):
52
  """Generate a mock answer for demonstration"""
 
55
 
56
  text = sample_content[content_id]["text"]
57
 
58
+ # Simple mock QA system
59
  question_words = set(question.lower().split())
60
  important_words = [word for word in question_words if len(word) > 3 and word not in ["what", "when", "where", "which", "how", "this", "that", "with", "from", "have", "about"]]
61
 
 
104
 
105
  with gr.Tab("Summarize"):
106
  summary_button = gr.Button("Generate Summary")
107
+ summary_output = gr.Textbox(label="Summary", lines=3)
108
 
109
  summary_button.click(
110
  fn=get_summary,
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
- transformers
2
  gradio==5.29.0
3
- firebase-admin
 
 
 
 
1
  gradio==5.29.0
2
+ transformers==4.28.0
3
+ torch==2.0.0
4
+ sentencepiece