|
|
|
"""OpenAI Whisper from Hugging Face Transformers with Microsoft PHI 3 Integration""" |
|
|
|
import gradio as gr |
|
from transformers import pipeline |
|
import torch |
|
from huggingface_hub import InferenceClient |
|
import os |
|
|
|
|
|
client = InferenceClient( |
|
"microsoft/Phi-3.5-mini-instruct", |
|
token=os.getenv("HF_API_TOKEN", "") |
|
) |
|
|
|
|
|
device = 'cuda' if torch.cuda.is_available() else 'cpu' |
|
|
|
|
|
whisper = pipeline('automatic-speech-recognition', model='openai/whisper-tiny', device=0 if device == 'cuda' else -1) |
|
|
|
|
|
instructions = os.getenv("INST", "Your default instructions here.") |
|
|
|
def query_phi(prompt): |
|
response = "" |
|
for message in client.chat_completion( |
|
messages=[{"role": "user", "content": f"{instructions}\n{prompt}"}], |
|
max_tokens=500, |
|
stream=True, |
|
): |
|
response += message.choices[0].delta.content |
|
return response |
|
|
|
def transcribe_and_query(audio): |
|
|
|
transcription = whisper(audio)["text"] |
|
transcription = "Prompt : " + transcription |
|
|
|
phi_response = query_phi(transcription) |
|
|
|
return transcription, phi_response |
|
|
|
|
|
iface = gr.Interface( |
|
fn=transcribe_and_query, |
|
inputs=gr.Audio(type="filepath"), |
|
outputs=["text", "text"], |
|
title="Scam Call detector with BEEP", |
|
description="Upload your recorded call to see if it is a scam or not. /n Stay Safe, Stay Secure." |
|
) |
|
|
|
|
|
iface.launch(share=True) |