MODEL_NAME = "gemini-1.5-pro-latest"
MAX_CONTEXT_LENGTH = 1048576 # 1M tokens
MAX_OUTPUT_TOKENS = 8192 # 8K tokens
generation_config = {
'temperature': 0.7, # Balance between creativity and precision
'top_p': 0.8, # Nucleus sampling for response diversity
'top_k': 40 # Top candidates for token selection
}
-
temperature: Controls randomness in generation
- 0.7 provides balanced output
- Lower = more focused
- Higher = more creative
-
top_p: Nucleus sampling threshold
- 0.8 maintains coherent output
- Affects vocabulary diversity
- Balances novelty and relevance
-
top_k: Token candidate limit
- 40 ensures diverse yet focused responses
- Prevents random divergence
- Maintains context relevance
def smart_truncate_text(text: str, max_length: int) -> str:
"""
Intelligently truncates text at sentence boundaries
- Maintains coherent content
- Preserves complete sentences
- Calculates retention percentage
"""
def process_transcript(transcript_data: List[Dict]) -> str:
"""
Processes raw transcript data
- Combines segments
- Maintains time information
- Formats for analysis
"""
ANALYSIS_TYPES = {
"Summary & Key Points": {
"prompt_template": ...,
"response_format": ...,
"processing_priority": "comprehensive"
},
"Title Suggestions": {
"prompt_template": ...,
"response_format": ...,
"processing_priority": "creative"
}
# Additional types...
}
async def generate_response(prompt: str, context: str) -> str:
"""
Generates AI response
- Applies context
- Formats output
- Handles errors
"""
def export_to_word(content: str) -> Document:
"""
Creates formatted Word document
- Applies styling
- Includes metadata
- Structures content
"""
def export_to_text(content: str) -> str:
"""
Formats plain text export
- Maintains structure
- Includes metadata
- Preserves formatting
"""
try:
response = await model.generate_content(prompt)
except Exception as e:
handle_api_error(e)
def validate_content(content: str) -> bool:
"""
Validates content quality
- Checks completeness
- Verifies format
- Ensures coherence
"""
- Efficient handling of large transcripts
- Smart context window management
- Optimal token usage
- Session state management
- Result persistence
- Efficient retrieval
- Environment variable usage
- Secure key storage
- Access control
- URL sanitization
- Content verification
- Error prevention
- Component validation
- Function verification
- Error handling checks
- API interaction testing
- Content flow validation
- UI functionality verification
# Environment configuration
load_dotenv()
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
YOUTUBE_API_KEY = os.getenv("YOUTUBE_API_KEY")
# Streamlit setup
st.set_page_config(
page_title="Gemini Flash YouTube Video Insights Pro",
page_icon="⚡",
layout="wide"
)
- Batch processing support
- Multi-video analysis
- Extended API integration
- Additional analysis types
- Enhanced visualization
- Advanced export options