birgermoell commited on
Commit
03ef4b7
1 Parent(s): c9fb98c

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +88 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+
4
+ import tempfile
5
+ import os
6
+
7
+ # Set up the Streamlit app
8
+ st.title("Triplet Audio Transcription and Journal Structuring App")
9
+
10
+ # Make an image for the app with the triplet.png image
11
+ st.image("triplet3.png", width=600)
12
+ st.write("Upload an audio file, and we'll transcribe it and structure the output as a journal entry.")
13
+
14
+ # Supported audio file formats
15
+ SUPPORTED_FORMATS = ['flac', 'm4a', 'mp3', 'mp4', 'mpeg', 'mpga', 'oga', 'ogg', 'wav', 'webm']
16
+
17
+ # Input field for OpenAI API key
18
+ api_key = st.text_input("Enter your OpenAI API key:", type="password")
19
+
20
+ st.write("Everything is open source, please clone and run locally. Bring your own API key. We are using base whisper and chat-gpt models from OpenAI. The app is built using Streamlit and Python. (Note: This app is for demonstration purposes only. Do not upload sensitive information.")
21
+
22
+
23
+ if api_key:
24
+ # Initialize OpenAI client with the API key
25
+ client = openai.OpenAI(api_key=api_key)
26
+
27
+ # Function to transcribe audio using OpenAI Whisper
28
+ def transcribe_audio(file_path):
29
+ try:
30
+ with open(file_path, "rb") as audio_file:
31
+ transcript = client.audio.transcriptions.create(
32
+ file=audio_file,
33
+ model="whisper-1",
34
+ response_format="verbose_json"
35
+ )
36
+ transcription = transcript.text
37
+ return transcription
38
+ except Exception as e:
39
+ st.error(f"Error in transcription: {e}")
40
+ return None
41
+
42
+ # Function to structure transcription as a journal entry using Chat-GPT
43
+ def structure_as_journal(transcription):
44
+ try:
45
+ prompt = f"Structure the following transcription as a detailed journal entry:\n\n{transcription}"
46
+ response = client.chat.completions.create(
47
+ model="gpt-3.5-turbo",
48
+ messages=[
49
+ {"role": "system", "content": "You are a helpful assistant."},
50
+ {"role": "user", "content": prompt}
51
+ ],
52
+ max_tokens=1024
53
+ )
54
+ journal_entry = response.choices[0].message.content
55
+ return journal_entry
56
+ except Exception as e:
57
+ st.error(f"Error in structuring journal entry: {e}")
58
+ return None
59
+
60
+ # File uploader for audio files
61
+ uploaded_file = st.file_uploader("Upload an audio file", type=SUPPORTED_FORMATS)
62
+
63
+ if uploaded_file:
64
+ # Save uploaded file temporarily
65
+ with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as temp_file:
66
+ temp_file.write(uploaded_file.read())
67
+ temp_file_path = temp_file.name
68
+
69
+ # Transcribe audio
70
+ st.write("Transcribing audio...")
71
+ transcription = transcribe_audio(temp_file_path)
72
+
73
+ if transcription:
74
+ st.write("Transcription:")
75
+ st.write(transcription)
76
+
77
+ # Structure transcription as a journal entry
78
+ st.write("Structuring as a journal entry...")
79
+ journal_entry = structure_as_journal(transcription)
80
+
81
+ if journal_entry:
82
+ st.write("Journal Entry:")
83
+ st.write(journal_entry)
84
+
85
+ # Clean up temporary file
86
+ os.remove(temp_file_path)
87
+ else:
88
+ st.warning("Please enter your OpenAI API key to proceed.")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai
2
+ streamlit