|
import streamlit as st |
|
import requests |
|
import pyttsx3 |
|
|
|
|
|
engine = pyttsx3.init() |
|
|
|
|
|
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}" |
|
|
|
|
|
def read_aloud(text): |
|
engine.say(text) |
|
engine.runAndWait() |
|
|
|
|
|
st.set_page_config(page_title="VisionAid", layout="centered") |
|
st.title("VisionAid") |
|
|
|
|
|
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) |
|
|
|
|
|
dark_mode = st.checkbox("Enable Dark Mode") |
|
if dark_mode: |
|
st.markdown("<style>body {background-color: black; color: white;}</style>", unsafe_allow_html=True) |
|
|
|
|
|
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!") |
|
|
|
|
|
st.info("Adjust text size, enable dark mode, summarize text, and read it aloud.") |
|
|