Sebbe33 commited on
Commit
f91380b
·
verified ·
1 Parent(s): 835bf99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -32
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import os
2
  import tempfile
3
-
4
  import streamlit as st
5
  from google import genai
6
  from jinja2 import Template
@@ -46,37 +45,18 @@ if st.button("Generate Transcript"):
46
  # Upload audio file
47
  uploaded_file = client.files.upload(file=tmp_file_path)
48
 
49
- # Create prompt template
50
- prompt_template = Template("""Generate a transcript of the episode. Include timestamps and identify speakers.
51
-
52
- Speakers are:
53
- {% for speaker in speakers %}- {{ speaker }}{% if not loop.last %}\n{% endif %}{% endfor %}
54
-
55
- eg:
56
- [00:00] Brady: Hello there.
57
- [00:02] Tim: Hi Brady.
58
-
59
- It is important to include the correct speaker names. Use the names you identified earlier. If you really don't know the speaker's name, identify them with a letter of the alphabet, eg there may be an unknown speaker 'A' and another unknown speaker 'B'.
60
-
61
- If there is music or a short jingle playing, signify like so:
62
- [01:02] [MUSIC] or [01:02] [JINGLE]
63
-
64
- If you can identify the name of the music or jingle playing then use that instead, eg:
65
- [01:02] [Firework by Katy Perry] or [01:02] [The Sofa Shop jingle]
66
 
67
- If there is some other sound playing try to identify the sound, eg:
68
- [01:02] [Bell ringing]
69
-
70
- Each individual caption should be quite short, a few short sentences at most.
71
-
72
- Signify the end of the episode with [END].
73
-
74
- Don't use any markdown formatting, like bolding or italics.
75
-
76
- Only use characters from the English alphabet, unless you genuinely believe foreign characters are correct.
77
-
78
- It is important that you use the correct words and spell everything correctly. Use the context of the podcast to help.
79
- If the hosts discuss something like a movie, book or celebrity, make sure the movie, book, or celebrity name is spelled correctly.""")
80
 
81
  prompt = prompt_template.render(speakers=speakers)
82
 
@@ -93,4 +73,11 @@ If the hosts discuss something like a movie, book or celebrity, make sure the mo
93
  except Exception as e:
94
  st.error(f"An error occurred: {str(e)}")
95
  finally:
96
- os.remove(tmp_file_path)
 
 
 
 
 
 
 
 
1
  import os
2
  import tempfile
 
3
  import streamlit as st
4
  from google import genai
5
  from jinja2 import Template
 
45
  # Upload audio file
46
  uploaded_file = client.files.upload(file=tmp_file_path)
47
 
48
+ # New token counting functionality
49
+ try:
50
+ token_info = client.models.count_tokens(
51
+ model='gemini-2.0-flash',
52
+ contents=[uploaded_file]
53
+ )
54
+ st.info(f"File contains approximately {token_info.total_tokens} tokens")
55
+ except AttributeError:
56
+ st.warning("Token counting not available in current API version")
 
 
 
 
 
 
 
 
57
 
58
+ # Create prompt template
59
+ prompt_template = Template("""[...your existing template here...]""")
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  prompt = prompt_template.render(speakers=speakers)
62
 
 
73
  except Exception as e:
74
  st.error(f"An error occurred: {str(e)}")
75
  finally:
76
+ os.remove(tmp_file_path)
77
+
78
+ # Credits section in sidebar
79
+ st.sidebar.markdown("""
80
+ **Credits**
81
+ - Transcription powered by [Gemini API](https://ai.google.dev/)
82
+ - Heavy inspired by https://github.com/philschmid/gemini-samples/blob/main/examples/gemini-transcribe-with-timestamps.ipynb
83
+ """)