File size: 1,804 Bytes
10739e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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"<style>body {{font-size: {text_size}%;}}</style>", unsafe_allow_html=True)

# Theme options
dark_mode = st.checkbox("Enable Dark Mode")
if dark_mode:
    st.markdown("<style>body {background-color: black; color: white;}</style>", 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.")