lodhrangpt commited on
Commit
36def4c
·
verified ·
1 Parent(s): af44622

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -10
app.py CHANGED
@@ -50,18 +50,28 @@ def generate_notes(transcript):
50
  except LookupError:
51
  sentences = custom_sent_tokenize(transcript)
52
 
53
- long_questions = [f"What is meant by '{sentence}'?" for sentence in sentences[:5]]
54
- short_questions = [f"Define '{sentence.split()[0]}'." for sentence in sentences[:5]]
55
 
 
 
 
 
56
  mcqs = []
57
  for sentence in sentences[:5]:
58
- mcq = {
59
- "question": f"What is '{sentence.split()[0]}'?",
60
- "options": [sentence.split()[0]] + random.sample(["Option 1", "Option 2", "Option 3"], 3),
61
- "answer": sentence.split()[0]
62
- }
63
- mcqs.append(mcq)
64
-
 
 
 
 
 
 
65
  pdf_path = create_pdf(transcript, long_questions, short_questions, mcqs)
66
  return pdf_path
67
 
@@ -69,24 +79,29 @@ def create_pdf(transcript, long_questions, short_questions, mcqs):
69
  pdf = FPDF()
70
  pdf.add_page()
71
 
 
72
  pdf.set_font("Arial", "B", 16)
73
- pdf.cell(200, 10, "Transcription Notes", ln=True, align="C")
74
 
 
75
  pdf.set_font("Arial", "", 12)
76
  pdf.multi_cell(0, 10, f"Transcription:\n{transcript.encode('latin1', 'replace').decode('latin1')}\n\n")
77
 
 
78
  pdf.set_font("Arial", "B", 14)
79
  pdf.cell(200, 10, "Long Questions", ln=True)
80
  pdf.set_font("Arial", "", 12)
81
  for question in long_questions:
82
  pdf.multi_cell(0, 10, f"- {question.encode('latin1', 'replace').decode('latin1')}\n")
83
 
 
84
  pdf.set_font("Arial", "B", 14)
85
  pdf.cell(200, 10, "Short Questions", ln=True)
86
  pdf.set_font("Arial", "", 12)
87
  for question in short_questions:
88
  pdf.multi_cell(0, 10, f"- {question.encode('latin1', 'replace').decode('latin1')}\n")
89
 
 
90
  pdf.set_font("Arial", "B", 14)
91
  pdf.cell(200, 10, "Multiple Choice Questions (MCQs)", ln=True)
92
  pdf.set_font("Arial", "", 12)
@@ -121,6 +136,7 @@ iface = gr.Interface(
121
  inputs=gr.Audio(type="filepath"),
122
  outputs=gr.File(label="Download PDF with Notes or Error Report"),
123
  title="Voice to Text Converter and Notes Generator",
 
124
  )
125
 
126
  iface.launch()
 
50
  except LookupError:
51
  sentences = custom_sent_tokenize(transcript)
52
 
53
+ # Generate long questions
54
+ long_questions = [f"Explain the concept discussed in: '{sentence}'." for sentence in sentences[:5]]
55
 
56
+ # Generate short questions
57
+ short_questions = [f"What does '{sentence.split()[0]}' mean in the context of this text?" for sentence in sentences[:5]]
58
+
59
+ # Generate MCQs with relevant distractors
60
  mcqs = []
61
  for sentence in sentences[:5]:
62
+ if len(sentence.split()) > 1: # Ensure there are enough words to create meaningful options
63
+ key_word = sentence.split()[0] # Use the first word as a key term
64
+ distractors = ["Term A", "Term B", "Term C"] # Replace with relevant terms if needed
65
+ options = [key_word] + distractors
66
+ random.shuffle(options) # Shuffle options for randomness
67
+ mcq = {
68
+ "question": f"What is '{key_word}' based on the context?",
69
+ "options": options,
70
+ "answer": key_word
71
+ }
72
+ mcqs.append(mcq)
73
+
74
+ # Generate and save a structured PDF
75
  pdf_path = create_pdf(transcript, long_questions, short_questions, mcqs)
76
  return pdf_path
77
 
 
79
  pdf = FPDF()
80
  pdf.add_page()
81
 
82
+ # Add title
83
  pdf.set_font("Arial", "B", 16)
84
+ pdf.cell(200, 10, "Transcription Notes and Questions", ln=True, align="C")
85
 
86
+ # Add transcription content
87
  pdf.set_font("Arial", "", 12)
88
  pdf.multi_cell(0, 10, f"Transcription:\n{transcript.encode('latin1', 'replace').decode('latin1')}\n\n")
89
 
90
+ # Add long questions
91
  pdf.set_font("Arial", "B", 14)
92
  pdf.cell(200, 10, "Long Questions", ln=True)
93
  pdf.set_font("Arial", "", 12)
94
  for question in long_questions:
95
  pdf.multi_cell(0, 10, f"- {question.encode('latin1', 'replace').decode('latin1')}\n")
96
 
97
+ # Add short questions
98
  pdf.set_font("Arial", "B", 14)
99
  pdf.cell(200, 10, "Short Questions", ln=True)
100
  pdf.set_font("Arial", "", 12)
101
  for question in short_questions:
102
  pdf.multi_cell(0, 10, f"- {question.encode('latin1', 'replace').decode('latin1')}\n")
103
 
104
+ # Add MCQs
105
  pdf.set_font("Arial", "B", 14)
106
  pdf.cell(200, 10, "Multiple Choice Questions (MCQs)", ln=True)
107
  pdf.set_font("Arial", "", 12)
 
136
  inputs=gr.Audio(type="filepath"),
137
  outputs=gr.File(label="Download PDF with Notes or Error Report"),
138
  title="Voice to Text Converter and Notes Generator",
139
+ description="This app converts audio to text and generates academic questions including long, short, and multiple-choice questions."
140
  )
141
 
142
  iface.launch()