importosfromfaster_whisperimportWhisperModelimportrequestsimportjson# 1. LOCAL TRANSCRIPTION (Whisper)
deftranscribe_audio(audio_path):print("Transcribing audio locally...")model=WhisperModel("base",device="cpu",compute_type="int8")segments,info=model.transcribe(audio_path,beam_size=5)transcript="".join([segment.textforsegmentinsegments])returntranscript# 2. LOCAL AI PROCESSING (Ollama + Llama 3)
defstructure_recipe(raw_transcript):print("Structuring recipe with local Llama 3...")url="http://localhost:11434/api/generate"system_prompt=("You are a helpful culinary archivist. Your job is to take a messy, conversational ""audio transcript from a grandparent and turn it into a beautifully structured recipe. ""Extract the Title, a brief heartwarming description, Ingredients with measurements, ""and Step-by-Step Instructions. Do not add any conversational filler in your final response.")payload={"model":"llama3","prompt":f"{system_prompt}\n\nTranscript: {raw_transcript}","stream":False}response=requests.post(url,json=payload)returnresponse.json()['response']# 3. RUN THE PIPELINE
if__name__=="__main__":audio_file="grandpas_spaghetti_story.mp3"ifos.path.exists(audio_file):raw_text=transcribe_audio(audio_file)final_recipe=structure_recipe(raw_text)withopen("heirloom_recipe.md","w")asf:f.write(final_recipe)print("Success! Your structured recipe is ready in heirloom_recipe.md")else:print(f"Please place an audio file named '{audio_file}' in this directory.")
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)