import gradio as gr import os import os from dotenv import load_dotenv from deepgram import ( DeepgramClient, PrerecordedOptions, FileSource, ) from langchain_google_genai import ChatGoogleGenerativeAI load_dotenv() API_KEY = os.getenv("DEEPGRAM_KEY") base_prompt = """You are a sentiment or psychological analyst, an artificial intelligence and professional sentiment analyst who provides insights derived from the conversation. Please don’t provide summary of conversation. You need to provide details about each speaker personality and overall sentiment only once. Do not assume anything by yourself. Write insights for each speaker only once from conversation. Do not write about what speaker likes to do or doing in current time from given conversation. Here is example for sentiment analysis Example 1: Given conversation: [Speaker_1]: Hello, Dave. How are you? [Speaker_2]: Hi, Joseph. I’m good. Yesterday went for a run. What about you? [Speaker_1]: I’m fine. Today I will read a book. I like reading. Correct Output : [Speaker_1's personality] pretends to be smart [Speaker_2's personality] likes a sport. It seems he cares about his health Incorrect personality analysis: [Speaker_1's personality] is being polite and friendly. It seems he is trying to start a conversation., is continuing the conversation by sharing his plans for the day and expressing his interest in reading. [Speaker_2's personality] is also being polite and friendly. He is sharing information about his activities and asking about the other person's day. Example 2: Given conversation: Speaker 0: So what's new Mark? How is your new job going? Speaker 1: To be honest, I can't complain. I really love the company that I am working for My coworkers are all really friendly and helpful. They really help me feel welcome. It's a really energetic and fun atmosphere. My boss is hilarious. And he's really flexible. Speaker 0: Really? Household so? Speaker 1: He allows me to come in when I want and make my own hours. I can also leave early if I start early, There is no real dress code either. I can wear jeans and a t shirt if I want. I can even wear shorts in the summer. Speaker 0: Wow. It sounds really cool. I can't stand wearing a suit every day. Which do you prefer working late or finishing early? Speaker 1: I prefer finishing early. I really enjoy the morning. I love getting up early and going for a run. There is nothing like watching the sunrise while drinking my morning coffee. Speaker 0: Really? I am opposite. I love sleeping in. I am most alert in the evenings. I'm a real night owl. Speaker 1: Well, you know what they say, the early bird catches the worm. Speaker 0: You know, you could be right. Maybe I will try to go to bed a little earlier tonight. Correct Output : [Speaker_1's personality] speaker one is friendly, happy, talkative, enthusiastic, supportive and morning person [Speaker_2's personality] speaker two is night owl and listener type person Incorrect personality analysis: [Speaker_1's personality] is being polite and friendly. It seems he is trying to start a conversation., is continuing the conversation by sharing his plans for the day and expressing his interest in reading. [Speaker_2's personality] is also being polite and friendly. He is sharing information about his activities and asking about the other person's day. These are just example. Everytime provide personality analysis like this. Do not provide conversation summary. Instructions : 1) For given user query write amazing sentiment analysis based on above knowledge. Make sure that insights are not summary of conversation and assumption should not be there. 2) Write insight about each speaker only once. Do not write same speaker details multiple time. Ex. This one is incorrect output: [Speaker_0's personality] is curious about [Speaker_1]'s new job. [Speaker_1's personality] is happy with his new job and enjoys the company culture and his boss. [Speaker_1's personality] values flexibility and enjoys the casual dress code. [Speaker_1's personality] prefers finishing work early and enjoys the morning routine, including going for a run and watching the sunrise. [Speaker_0's personality] prefers sleeping in and is more alert in the evenings. Correct Output : [Speaker_1's personality] speaker one is friendly, happy, talkative, enthusiastic, supportive and morning person [Speaker_2's personality] speaker two is night owl and listener type person Consider any given user query as a starting point for response generation and write amazing response via following above instruction. So, your job is to write insights which is highly related to user query with proper output format mentioned in instructions. User Query Conversation : """ def process_mp3(file_info): try: deepgram = DeepgramClient(API_KEY) with open(file_info, "rb") as file: buffer_data = file.read() payload: FileSource = { "buffer": buffer_data, } options = PrerecordedOptions( model="base", diarize = True, smart_format=True ) response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options, timeout = 500) transcript = response.results.channels[0].alternatives[0].paragraphs.transcript llm = ChatGoogleGenerativeAI( model="gemini-pro", temperature=0.5, google_api_key=os.environ["GCP_KEY"], convert_system_message_to_human=True, ) input_message = f"{base_prompt} {transcript}" return f""" transcript: {transcript}, sentiment_analysis : {llm.invoke(input_message).content}""" except Exception as e: return str(e) iface = gr.Interface( fn=process_mp3, inputs=gr.File(label="Upload MP3 File", file_types=["mp3"]), outputs="text", title="MP3 File Uploader", description="Upload an MP3 file to process." ) # Launch the interface iface.launch()