lodhrangpt commited on
Commit
6f873e0
·
verified ·
1 Parent(s): dfbfcd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -23,7 +23,7 @@ def transcribe(audio_path):
23
 
24
  groq_api_endpoint = "https://api.groq.com/openai/v1/audio/transcriptions"
25
  headers = {
26
- "Authorization": "Bearer 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", # Replace with your actual API key
27
  }
28
  files = {
29
  'file': ('audio.wav', audio_data, 'audio/wav'),
@@ -55,11 +55,15 @@ def generate_exam_paper(transcript):
55
  important_sentences = get_important_sentences(sentences)
56
 
57
  # Generate exam-like questions
58
- long_questions = [f"Explain the historical significance of '{sentence}'?" for sentence in important_sentences[:5]]
59
- short_questions = [f"What is the definition of '{sentence.split()[0]}'?" for sentence in important_sentences[:5]]
60
-
61
  mcqs = generate_mcqs(important_sentences)
62
 
 
 
 
 
 
63
  pdf_path = create_pdf(transcript, long_questions, short_questions, mcqs)
64
  return pdf_path
65
 
@@ -70,11 +74,24 @@ def get_important_sentences(sentences):
70
  # Simplified heuristic: sentences with important nouns/verbs
71
  if len(re.findall(r'\b(NN|VB)\b', sentence)): # Using POS tags to detect nouns/verbs
72
  important_sentences.append(sentence)
73
- return important_sentences[:5] # Limit to top 5 important sentences
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  def generate_mcqs(important_sentences):
76
  mcqs = []
77
- for sentence in important_sentences:
78
  # Generate MCQs from the sentence context
79
  key_terms = sentence.split() # Simple tokenization
80
  correct_answer = random.choice(key_terms) # Select a key term as the answer
 
23
 
24
  groq_api_endpoint = "https://api.groq.com/openai/v1/audio/transcriptions"
25
  headers = {
26
+ "Authorization": "Bearer YOUR_API_KEY", # Replace with your actual API key
27
  }
28
  files = {
29
  'file': ('audio.wav', audio_data, 'audio/wav'),
 
55
  important_sentences = get_important_sentences(sentences)
56
 
57
  # Generate exam-like questions
58
+ long_questions = generate_long_questions(important_sentences)
59
+ short_questions = generate_short_questions(important_sentences)
 
60
  mcqs = generate_mcqs(important_sentences)
61
 
62
+ # Ensure there are exactly 2 long questions, 5 short questions, and 7 MCQs
63
+ long_questions = long_questions[:2] # Limit to 2 long questions
64
+ short_questions = short_questions[:5] # Limit to 5 short questions
65
+ mcqs = mcqs[:7] # Limit to 7 MCQs
66
+
67
  pdf_path = create_pdf(transcript, long_questions, short_questions, mcqs)
68
  return pdf_path
69
 
 
74
  # Simplified heuristic: sentences with important nouns/verbs
75
  if len(re.findall(r'\b(NN|VB)\b', sentence)): # Using POS tags to detect nouns/verbs
76
  important_sentences.append(sentence)
77
+ return important_sentences
78
+
79
+ def generate_long_questions(important_sentences):
80
+ long_questions = []
81
+ for sentence in important_sentences[:2]: # Limit to 2 long questions
82
+ long_questions.append(f"Explain the historical significance of '{sentence}'?")
83
+ return long_questions
84
+
85
+ def generate_short_questions(important_sentences):
86
+ short_questions = []
87
+ for sentence in important_sentences[:5]: # Limit to 5 short questions
88
+ # Use the first word of the sentence to create short questions
89
+ short_questions.append(f"What is the definition of '{sentence.split()[0]}'?")
90
+ return short_questions
91
 
92
  def generate_mcqs(important_sentences):
93
  mcqs = []
94
+ for sentence in important_sentences[:7]: # Limit to 7 MCQs
95
  # Generate MCQs from the sentence context
96
  key_terms = sentence.split() # Simple tokenization
97
  correct_answer = random.choice(key_terms) # Select a key term as the answer