Update app.py
Browse files26 unmodified lines272829303031323352 unmodified lines86878889909192933 unmodified lines979899981001011021034 unmodified lines1081091101091111121133 unmodified lines1171181191191201211221236 unmodified lines13013113213313413513613713826 unmodified lines# Load the Qwen model and tokenizerqwen_model_name = "Qwen/Qwen2.5-3B-Instruct"qwen_tokenizer = AutoTokenizer.from_pretrained(qwen_model_name, trust_remote_code=True)qwen_model = AutoModelForCausalLM.from_pretrained(qwen_model_name, trust_remote_code=True, torch_dtype=torch.float16).to(device)qwen_model = AutoModelForCausalLM.from_pretrained(qwen_model_name, trust_remote_code=True).to(device)
def download_audio_from_url(url): try:52 unmodified lines transcription = whisper_processor.batch_decode(predicted_ids, skip_special_tokens=True) print(f"Transcription complete. Length: {len(transcription[0])} characters") if len(transcription[0]) < 10: raise ValueError(f"Transcription too short: {transcription[0]}") return transcription[0] except Exception as e: print(f"Error in transcribe_audio: {str(e)}")3 unmodified lines print("Starting speaker separation...") prompt = f"""Analyze the following transcribed text and separate it into different speakers. Identify potential speaker changes based on context, content shifts, or dialogue patterns. Format the output as follows:
1. Label speakers as "Speaker 1", "Speaker 2", etc. You will have to use dialog context to asume which speaker is saying their dialog as that isn't in the text.1. Label speakers as "Speaker 1", "Speaker 2", etc.2. Start each speaker's text on a new line beginning with their label.3. Separate different speakers' contributions with a blank line.4. If the same speaker continues, do not insert a blank line or repeat the speaker label.4 unmodified lines""" inputs = qwen_tokenizer(prompt, return_tensors="pt").to(device) inputs = {k: v.to(torch.float16) for k, v in inputs.items()} # Convert inputs to float16 with torch.no_grad(): outputs = qwen_model.generate(**inputs, max_new_tokens=4000) result = qwen_tokenizer.decode(outputs[0], skip_special_tokens=True)3 unmodified lines print("Speaker separation complete.") return processed_text
def transcribe_video(url): try: print(f"Attempting to download audio from URL: {url}")6 unmodified lines os.unlink(temp_audio.name) if len(transcript) < 10: raise ValueError("Transcription too short, possibly failed") print("Separating speakers...") separated_transcript = separate_speakers(transcript) app.py+8-4