import streamlit as st import requests import pyttsx3 # Initialize TTS engine engine = pyttsx3.init() # Define Gemini API summarization function def summarize_text(text): api_key = "AIzaSyAUHjI-5L_s0RSs8sOKugDMY1_7cvVBhHw" url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key={api_key}" payload = {"contents": [{"parts": [{"text": text}]}]} headers = {"Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) if response.status_code == 200: return response.json().get("contents", [{}])[0].get("parts", [{}])[0].get("text", "") return f"Error: {response.status_code} - {response.text}" # TTS function def read_aloud(text): engine.say(text) engine.runAndWait() # Streamlit UI st.set_page_config(page_title="VisionAid", layout="centered") st.title("VisionAid") # Text size slider text_size = st.slider("Adjust Text Size", min_value=100, max_value=200, value=100) st.markdown(f"", unsafe_allow_html=True) # Theme options dark_mode = st.checkbox("Enable Dark Mode") if dark_mode: st.markdown("", unsafe_allow_html=True) # Input text for summarization text_input = st.text_area("Enter text to summarize:") if st.button("Summarize"): if text_input.strip(): with st.spinner("Summarizing..."): summary = summarize_text(text_input) st.success("Summary:") st.write(summary) if st.button("Read Summary Aloud"): read_aloud(summary) else: st.error("Please enter some text!") # Information st.info("Adjust text size, enable dark mode, summarize text, and read it aloud.")