Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from openai import OpenAI
|
2 |
+
from pydub import AudioSegment
|
3 |
+
import os
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
|
7 |
+
|
8 |
+
def extract_audio(video_file):
|
9 |
+
output_audio_file = "/content/demo1.mp3"
|
10 |
+
os.system(f"ffmpeg -i {video_file} -q:a 0 -map a {output_audio_file}")
|
11 |
+
return output_audio_file
|
12 |
+
|
13 |
+
def get_transcript(audio_file):
|
14 |
+
audio_file = open(audio_file, "rb")
|
15 |
+
transcript = client.audio.transcriptions.create(
|
16 |
+
file=audio_file,
|
17 |
+
model="whisper-1",
|
18 |
+
response_format="verbose_json",
|
19 |
+
)
|
20 |
+
return transcript.text
|
21 |
+
|
22 |
+
def detect_keywords(transcript, query):
|
23 |
+
completion = client.chat.completions.create(
|
24 |
+
model="gpt-4o-mini",
|
25 |
+
messages=[
|
26 |
+
{"role": "system", "content": "You are a helpful assistant that can detect the important keywords from a paragraph"},
|
27 |
+
{"role": "user", "content": f'''{query}
|
28 |
+
Please get me those variable words given in the sample speech transcript.
|
29 |
+
|
30 |
+
The provided transcript to detect and map those are:
|
31 |
+
|
32 |
+
#only give me the mapping from above transcript to below transcript as:
|
33 |
+
"customer name": "manas",
|
34 |
+
|
35 |
+
scan for all variables present inside <> signs, if some mapping isn't done or mentioned in the below one. at last mention this is missing and rerecord the video
|
36 |
+
|
37 |
+
{transcript}'''}
|
38 |
+
]
|
39 |
+
)
|
40 |
+
return completion.choices[0].message.content
|
41 |
+
|
42 |
+
def process_video(video_file):
|
43 |
+
audio_file = extract_audio(video_file)
|
44 |
+
transcript = get_transcript(audio_file)
|
45 |
+
query = '''मैं <Customer Name>, एचडीएफ़सी लाइफ़ से <Policy Term> वर्षों के लिए एक स्टैंड-अलोन बीमा पॉलिसी <Product Name>, <Life Assured Name> के नाम से ले रहा/रही हूं, जिनका फ़ोन नंबर <Life Assured Mobile no> है, जिसके लिए मुझे <premium amount excluding taxes > रुपये लागू करों के साथ में <Payment Mode> आधार पर <Premium Payment Term> साल तक अदा करने हैं। मुझे पता है कि अगर मैं पूरे प्रीमियम भुगतान अवधि के लिए प्रीमियम का भुगतान नहीं करता/करती हूं तो मुझे पॉलिसी के पुरे लाभ नहीं मिल सकते है | मैं जानता/जानती हूं कि 5 साल पूरे होने के बाद निकासी की अनुमति दी जाती है| मुझे पॉलिसी के लाभों की जानकारी है, कृपया ऐप्लिकेशन के प्रोसेस के लिए इसे मेरी सहमति मानें। मुझे जानकारी है कि मैं उत्पाद के सभी नियमों और शर्तों के बारे में जानने के लिए पॉलिसी दस्तावेज का संदर्भ लें सकता/सकती हूँ तथा किसी भी विसंगति के लिए फ्री लुक अवधि के दौरान मैं बीमाकर्ता या बैंक से संपर्क कर सकता/सकती हूँ। मैं एतद्द्वारा पुष्टि करता/करती हूं कि इस बीमा पॉलिसी को खरीदते समय विक्रेता द्वारा किसी अन्य बैंकिंग उत्पादों या सेवाओं के लिए मुझसे कोई वादा नहीं किया गया था। मैं अपने बीमा प्रस्ताव के तेजी से प्रसंस्करण की सुविधा के लिए एचडीएफसी बैंक से अपनी व्यक्तिगत जानकारी, जैसे कि फोन नंबर, ईमेल आईडी, पता, गैर नकद क्रेडिट, प्रोफ़ाइल आदि, प्राप्त करने के लिए एचडीएफसी लाइफ को अपनी सहमति देता हूं।'''
|
46 |
+
result = detect_keywords(transcript, query)
|
47 |
+
return result
|
48 |
+
|
49 |
+
# Define the Gradio interface
|
50 |
+
iface = gr.Interface(
|
51 |
+
fn=process_video,
|
52 |
+
inputs=gr.File(label="Upload a Video"),
|
53 |
+
outputs="text",
|
54 |
+
title="Video to Keyword Extractor",
|
55 |
+
description="Upload a video file, and the app will extract audio, transcribe it, and detect important keywords based on a predefined query."
|
56 |
+
)
|
57 |
+
|
58 |
+
if __name__ == "__main__":
|
59 |
+
iface.launch()
|