OmarHusseinZaki commited on
Commit
28eae3c
·
1 Parent(s): 725e2f6

add generating notes method

Browse files
Files changed (1) hide show
  1. main.py +49 -1
main.py CHANGED
@@ -183,4 +183,52 @@ def transcribe_audio(audio_bytes: bytes) -> str:
183
  except Exception as e:
184
  print(f"ERROR: Hugging Face ASR API call failed: {e}")
185
  # Check for specific HF error types if possible
186
- raise HTTPException(status_code=503, detail=f"Transcription service failed: {e}") # 503 Service Unavailable
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  except Exception as e:
184
  print(f"ERROR: Hugging Face ASR API call failed: {e}")
185
  # Check for specific HF error types if possible
186
+ raise HTTPException(status_code=503, detail=f"Transcription service failed: {e}") # 503 Service Unavailable
187
+
188
+
189
+ def generate_notes_from_transcript(transcript: str) -> str:
190
+ """
191
+ Sends the transcript to the Hugging Face text generation LLM API.
192
+ """
193
+ if not hf_inference:
194
+ raise HTTPException(status_code=503, detail="Note generation service client not initialized.")
195
+ if not transcript:
196
+ print("Warning: Skipping note generation for empty transcript.")
197
+ return "Could not generate notes: Transcription was empty."
198
+
199
+ print(f"Generating notes for transcript (length {len(transcript)}) using {LLM_MODEL}...")
200
+
201
+ # --- Prompt Engineering: Crucial for good results! ---
202
+ # Be explicit about the desired output format and role.
203
+ prompt = f"""You are an expert note-taking assistant specializing in extracting key information from video transcripts.
204
+ Please analyze the following transcript and generate concise, well-structured notes.
205
+ Focus on the main topics, key points, important examples, definitions, and any conclusions presented. Use bullet points or numbered lists for clarity.
206
+
207
+ Transcript:
208
+ \"\"\"
209
+ {transcript}
210
+ \"\"\"
211
+
212
+ Structured Notes:"""
213
+
214
+ try:
215
+ # Use the textGeneration task for instruction-following models like Mistral
216
+ response = hf_inference.text_generation(
217
+ prompt=prompt,
218
+ model=LLM_MODEL,
219
+ max_new_tokens=1024, # Max length of the *generated* notes. Adjust as needed.
220
+ # Longer videos might need more tokens for comprehensive notes.
221
+ temperature=0.7, # Controls randomness (lower = more focused, higher = more creative)
222
+ repetition_penalty=1.1, # Slightly discourage repeating the same phrases
223
+ # Other parameters like top_p, top_k can also be tuned
224
+ )
225
+
226
+ # The response is usually the generated text directly for text-generation
227
+ # Sometimes it might include the prompt, so basic cleaning can help.
228
+ notes = response.strip()
229
+ print("Note generation successful.")
230
+ return notes
231
+
232
+ except Exception as e:
233
+ print(f"ERROR: Hugging Face LLM API call failed: {e}")
234
+ raise HTTPException(status_code=503, detail=f"Note generation service failed: {e}")