DrishtiSharma commited on
Commit
70925ae
·
verified ·
1 Parent(s): 6f690fd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from openai import OpenAI
3
+ import os
4
+
5
+ # Load environment variables
6
+ load_dotenv()
7
+ MODEL = 'gpt-4'
8
+ client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
9
+
10
+ st.title('AUDIO ANALYZER')
11
+
12
+ # Upload audio file
13
+ audio_file = st.file_uploader("Upload an audio file", type=["mp3", "wav", "m4a"])
14
+
15
+ if audio_file:
16
+ # Display audio player
17
+ st.audio(audio_file)
18
+
19
+ # Transcribe audio
20
+ transcription = client.audio.transcriptions.create(
21
+ model="whisper-1",
22
+ file=audio_file,
23
+ )
24
+
25
+ # Analyze transcription
26
+ response = client.chat.completions.create(
27
+ model=MODEL,
28
+ messages=[
29
+ {"role": "system", "content": """You are an AI audio analyzer.
30
+ You are tasked to analyze the audio and create a summary of the provided transcription. Please respond in Markdown."""},
31
+ {"role": "user", "content": f"The audio transcription is: {transcription.text}"}
32
+ ],
33
+ temperature=0,
34
+ )
35
+
36
+ # Display the response
37
+ st.markdown(response.choices[0].message.content)