@@ -101,7 +104,7 @@

Transcript

Book cover @@ -111,30 +114,32 @@

Transcript

let quoteData = null; // run fetch post request every 5 seconds let recentQuoteData = null; + let isPlaying = false; - setInterval(() => { - fetch("/quote-data", { method: "GET" }) - .then((response) => response.json()) - .then((newQuoteData) => { - quoteData = newQuoteData; - if (quoteData === null) { - console.log("No new quote data"); - return; - } - // console.log(quoteData); - if (recentQuoteData && quoteData.text === recentQuoteData.text) { - // console.log("Quote data is the same as the previous one"); - return; - } - - recentQuoteData = quoteData; - animationDelay = getDelayBasedOnStringLength(quoteData.text); - - animateQuote(); - animateTranscript(); - }) - .catch((error) => console.error("Error:", error)); - }, 500); + // play the transcript + // setInterval(() => { + // fetch("/quote-data", { method: "GET" }) + // .then((response) => response.json()) + // .then((newQuoteData) => { + // quoteData = newQuoteData; + // if (quoteData === null) { + // console.log("No new quote data"); + // return; + // } + // // console.log(quoteData); + // if (recentQuoteData && quoteData.text === recentQuoteData.text) { + // // console.log("Quote data is the same as the previous one"); + // return; + // } + + // recentQuoteData = quoteData; + // animationDelay = getDelayBasedOnStringLength(quoteData.text); + + // animateQuote(); + // animateTranscript(); + // }) + // .catch((error) => console.error("Error:", error)); + // }, 500); diff --git a/pyproject.toml b/pyproject.toml index 9e9b994..9f4518b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ assemblyai = "^0.23.0" openai = "^1.14.0" requests = "^2.31.0" pyaudio = "^0.2.14" +flask = "^3.0.2" [build-system] diff --git a/server.py b/server.py new file mode 100644 index 0000000..a99693f --- /dev/null +++ b/server.py @@ -0,0 +1,33 @@ +from flask import Flask, request, jsonify +from transcriber.display_log_timestamp import send_quotes_to_server +import json +from flask_cors import CORS + + +app = Flask(__name__) +CORS(app, origins=["http://localhost:3000"]) + +@app.route('/', methods=['GET']) +def hello_world(): + return 'Hello, World!' + +@app.route('/send-quotes', methods=['POST']) +def send_quotes(): + print(request.json) + log_file = request.json['log_file'] + timestamp_file = request.json['timestamp_file'] + # open the log file and timestamp file + with open(log_file, 'r') as log_file: + log_file = json.load(log_file) + with open(timestamp_file, 'r') as timestamp_file: + timestamp_file = json.load(timestamp_file) + send_quotes_to_server(log_file, timestamp_file) + return jsonify({'message': 'Quotes sent to server'}) + +# run the flask app on port 5000 + +if __name__ == '__main__': + app.run(port=5000, debug=True) + + + diff --git a/transcriber/__pycache__/display_log_timestamp.cpython-39.pyc b/transcriber/__pycache__/display_log_timestamp.cpython-39.pyc new file mode 100644 index 0000000..b1442ae Binary files /dev/null and b/transcriber/__pycache__/display_log_timestamp.cpython-39.pyc differ diff --git a/transcriber/_transcriber.py b/transcriber/_transcriber.py index 4816595..b1b0321 100644 --- a/transcriber/_transcriber.py +++ b/transcriber/_transcriber.py @@ -64,11 +64,4 @@ def process(transcript, run): write_to_log(run, run_id=run['id']) print('Error occurred, writing to log...') print('Exiting...') - return run - - - - - -if __name__ == '__main__': - simulate_transcription_process() \ No newline at end of file + return run \ No newline at end of file diff --git a/transcriber/covers.json b/transcriber/covers.json new file mode 100644 index 0000000..50abeee --- /dev/null +++ b/transcriber/covers.json @@ -0,0 +1,12 @@ +{ + "The Untethered Soul: The Journey Beyond Yourself": "https://images-na.ssl-images-amazon.com/images/S/compressed.photo.goodreads.com/books/1354898395i/1963638.jpg", + "Writing Better Lyrics": "https://images-na.ssl-images-amazon.com/images/S/compressed.photo.goodreads.com/books/1387752921i/695626.jpg", + "Four Thousand Weeks: Time Management for Mortals": "https://images-na.ssl-images-amazon.com/images/S/compressed.photo.goodreads.com/books/1627425434i/54785515.jpg", + "101 Essays That Will Change The Way You Think": "https://images-na.ssl-images-amazon.com/images/S/compressed.photo.goodreads.com/books/1479346785i/32998876.jpg", + "Storyworthy: Engage, Teach, Persuade, and Change Your Life through the Power of Storytelling": "https://images-na.ssl-images-amazon.com/images/S/compressed.photo.goodreads.com/books/1514780933i/37786022.jpg", + "The Glass Bead Game": "https://images-na.ssl-images-amazon.com/images/S/compressed.photo.goodreads.com/books/1386922806i/16634.jpg", + "Hear Yourself: How to Find Peace in a Noisy World": "https://images-na.ssl-images-amazon.com/images/S/compressed.photo.goodreads.com/books/1640872731i/55200394.jpg", + "Getting Things Done: The Art of Stress-Free Productivity": "https://images-na.ssl-images-amazon.com/images/S/compressed.photo.goodreads.com/books/1312474060i/1633.jpg", + "On the Shortness of Life": "https://images-na.ssl-images-amazon.com/images/S/compressed.photo.goodreads.com/books/1619107079i/97412.jpg", + "Civilized to Death: The Price of Progress": "https://images-na.ssl-images-amazon.com/images/S/compressed.photo.goodreads.com/books/1453131888i/28596619.jpg" +} \ No newline at end of file diff --git a/transcriber/display_log_timestamp.py b/transcriber/display_log_timestamp.py index ba6ca67..7b71b88 100644 --- a/transcriber/display_log_timestamp.py +++ b/transcriber/display_log_timestamp.py @@ -147,8 +147,17 @@ def send_quotes_to_server(log_file, timestamp_file): transcript = step['data'] break + # read covers.json to get the book cover + with open('transcriber/covers.json', 'r') as covers: + covers = json.load(covers) + for cover in covers: + # key == book title + if cover == filtered_quotes[chosen_quote['index']]['title']: + book_cover = covers[cover] + break + - response = requests.post('http://localhost:3000/new-quote-data', json={'text': bolded_quote, 'author': filtered_quotes[chosen_quote['index']]['author'], 'title': filtered_quotes[chosen_quote['index']]['title'], 'reasoning': chosen_quote['reasoning'], 'transcript': timestamp['text'], 'transcript_times': timestamp['words'] }) + response = requests.post('http://localhost:3000/new-quote-data', json={'text': bolded_quote, 'author': filtered_quotes[chosen_quote['index']]['author'], 'title': filtered_quotes[chosen_quote['index']]['title'], 'reasoning': chosen_quote['reasoning'], 'transcript': timestamp['text'], 'transcript_times': timestamp['words'], 'cover': book_cover}) # write post requests to json file for testing # storage.append({