MonsterBoyTabs commited on
Commit
0337f54
·
verified ·
1 Parent(s): caabffd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -45
app.py CHANGED
@@ -1,16 +1,7 @@
1
  import streamlit as st
2
- from streamlit_mic_recorder import mic_recorder
3
- from openai import OpenAI
4
  import json
5
  from pathlib import Path
6
  from datetime import datetime
7
- import os
8
- from dotenv import load_dotenv
9
- import time
10
-
11
- # Load OpenAI API key
12
- load_dotenv()
13
- client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
14
 
15
  # Initialize session state for tasks
16
  if 'tasks' not in st.session_state:
@@ -22,42 +13,6 @@ if 'tasks' not in st.session_state:
22
  st.title("📚 Student Study Tracker")
23
  days = list(st.session_state.tasks.keys())
24
 
25
- # Voice input sidebar
26
- st.sidebar.header("🎤 Voice Input")
27
- current_day = datetime.today().strftime('%A')
28
- voice_note = mic_recorder(start_prompt="🎤 Add Task", stop_prompt="⏹️ Stop", key='recorder')
29
-
30
- # Process voice input with retry logic
31
- if voice_note and 'bytes' in voice_note:
32
- max_retries = 3 # Number of retries
33
- retry_delay = 2 # Delay between retries (in seconds)
34
-
35
- for attempt in range(max_retries):
36
- try:
37
- # Save the recorded audio to a temporary file
38
- audio_file = open("temp_audio.wav", "wb")
39
- audio_file.write(voice_note['bytes'])
40
- audio_file.close()
41
-
42
- # Transcribe using OpenAI Whisper
43
- with open("temp_audio.wav", "rb") as audio_file:
44
- transcript = client.audio.transcriptions.create(
45
- model="whisper-1",
46
- file=audio_file
47
- )
48
-
49
- # Add transcribed task to current day
50
- if transcript.text:
51
- st.session_state.tasks[current_day].append({'text': transcript.text, 'checked': False})
52
- st.sidebar.success(f"Added: {transcript.text}")
53
- break # Exit the retry loop if successful
54
- except Exception as e:
55
- if attempt < max_retries - 1: # Don't wait on the last attempt
56
- st.sidebar.warning(f"Attempt {attempt + 1} failed. Retrying in {retry_delay} seconds...")
57
- time.sleep(retry_delay)
58
- else:
59
- st.sidebar.error(f"Error: {str(e)}")
60
-
61
  # Progress bar
62
  completed_tasks = sum(
63
  sum(1 for task in st.session_state.tasks[day] if task['checked'])
 
1
  import streamlit as st
 
 
2
  import json
3
  from pathlib import Path
4
  from datetime import datetime
 
 
 
 
 
 
 
5
 
6
  # Initialize session state for tasks
7
  if 'tasks' not in st.session_state:
 
13
  st.title("📚 Student Study Tracker")
14
  days = list(st.session_state.tasks.keys())
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  # Progress bar
17
  completed_tasks = sum(
18
  sum(1 for task in st.session_state.tasks[day] if task['checked'])