Skip to content

Image Generator Code Integrated #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .streamlit/secrets.example.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[general]
YOUTUBE_VIDEO_ID=""
YOUTUBE_VIDEO_ID="dQw4w9WgXcQ"
ADMIN_EMAIL=""
ADMIN_NAME=""

Expand All @@ -14,11 +14,10 @@ server_metadata_url=""

[api_key]
GEMINI_API_KEY=""
GOOGLE_API_KEY=""
GROQ_API_KEY=""
GROQ_API_KEY = ""
NASA_API_KEY=""
NEWS_API_KEY=""
OpenAI_API_KEY=""
OpenAI_API_KEY="sk-"
SPOONACULAR_API_KEY=""
TMDB_API_KEY=""
UBERDUCK_API_KEY=""
Expand Down
47 changes: 23 additions & 24 deletions Jarvis.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import streamlit as st

import streamlit as st # type: ignore
from src.helpers.structPages import structPages
from src.helpers.getFolders import getFolders


def application():
pages = {
"": [
st.Page("src/apps/public/home.py", title="Home", icon=":material/home:"),
st.Page("src/apps/public/youtubePlaylist.py", title="Jarvis Videos", icon=":material/ondemand_video:"),
],
"Account": [
st.Page("src/apps/auth/auth.py", title="Authentication", icon=":material/lock_open:"),
],
}
pages = {
"": [
st.Page("src/apps/public/home.py",
title="Home", icon=":material/home:"),
st.Page("src/apps/public/youtubePlaylist.py",
title="Jarvis Videos", icon=":material/ondemand_video:"),
],
"Account": [
st.Page("src/apps/auth/auth.py", title="Authentication",
icon=":material/lock_open:"),
],
}

if st.user and st.user.is_logged_in:
MAIN_DIR = "src/apps/pages"
folders = getFolders(MAIN_DIR)
if folders:
for folder_name, folder_dir in folders.items():
pages[folder_name.title()] = structPages(f"{MAIN_DIR}/{folder_dir}")
# Check if st has the "user" attribute and if the user is logged in
if hasattr(st, "user") and getattr(st.user, "is_logged_in", False):
MAIN_DIR = "src/apps/pages"
folders = getFolders(MAIN_DIR)
if folders:
for folder_name, folder_dir in folders.items():
pages[folder_name.title()] = structPages(
f"{MAIN_DIR}/{folder_dir}")

if st.user.email == st.secrets["general"]["ADMIN_EMAIL"] and st.user.given_name == st.secrets["general"]["ADMIN_NAME"]:
pages.update({
"Admin": [
st.Page("src/apps/auth/env.py", title="Environment Variables", icon=":material/security:"),
]
})
return st.navigation(pages)

return st.navigation(pages)

application().run()
7 changes: 0 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
Authlib
deep-translator
faiss-cpu
google-generativeai
groq
kaggle
langchain_community
langchain_core
langchain_google_genai
langchain_groq
langchain_text_splitters
matplotlib
Pint
plotly
pygame
pymultidictionary
pypdf
PyPDF2
pyperclip
pyshorteners
Expand Down
87 changes: 65 additions & 22 deletions src/apps/auth/auth.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,74 @@
from datetime import datetime
import streamlit as st
import streamlit as st # type: ignore
from time import sleep
import pytz

import toml # type: ignore
import types
from src.utils.greeting import GreetUser

def unix_to_ist(timestamp):
india_tz = pytz.timezone('Asia/Kolkata')
format_str = '%I:%M:%S %p IST'
return datetime.fromtimestamp(timestamp, pytz.utc).astimezone(india_tz).strftime(format_str)
# ────────────────────────────────────────────────────────────
# 1) Local‐dev stubs for st.user / st.login / st.logout
# so you never hit StreamlitAuthError when you run this app locally.
if not hasattr(st, "user"):
st.user = types.SimpleNamespace(
is_logged_in=False,
given_name="Developer",
name="Local Dev",
email="[email protected]",
picture="https://via.placeholder.com/150",
)

try:
with open("secrets.example.toml", "r") as f:
secrets = toml.load(f)
except FileNotFoundError:
secrets = {}

# Check if real Google creds are configured in secrets.toml
google_cfg = secrets.get("google", {})
if not google_cfg.get("clientId") or not google_cfg.get("clientSecret"):
# No OAuth creds → stub out login/logout
def _dummy_login(provider: str):
st.user.is_logged_in = True

def _dummy_logout():
st.user.is_logged_in = False

st.login = _dummy_login
st.logout = _dummy_logout
# ────────────────────────────────────────────────────────────


def unix_to_ist(timestamp: float) -> str:
india_tz = pytz.timezone("Asia/Kolkata")
fmt = '%I:%M:%S %p IST'
return (
datetime.fromtimestamp(timestamp, pytz.utc)
.astimezone(india_tz)
.strftime(fmt)
)


def auth():
if st.user and not st.user.is_logged_in:
st.title("🔐 Login Required")
st.write("Please authenticate using your Google account to access your profile.")
if st.button("🔓 Authenticate with Google"):
st.login("google")

else:
st.title(f"🙏 {GreetUser(st.user.given_name)}")
st.success("Welcome to Jarvis AI Assistant!", icon="🤝")
st.image(st.user.picture, caption=st.user.name)
st.write("Email:", st.user.email)

if st.button("Log out"):
st.toast(f"Goodbye, {st.user.name}! See you soon!", icon="🚪")
sleep(2)
st.logout()
user = st.user

if not user.is_logged_in:
st.title("🔐 Login Required")
st.write(
"Please authenticate using your Google account to access your profile.")
if st.button("🔓 Authenticate with Google"):
st.login("google")

else:
st.title(f"🙏 {GreetUser(user.given_name)}")
st.success("Welcome to Jarvis AI Assistant!", icon="🤝")
st.image(user.picture, caption=user.name)
st.write("Email:", user.email)

if st.button("Log out"):
st.toast(f"Goodbye, {user.name}! See you soon!", icon="🚪")
sleep(2)
st.logout()


auth()
41 changes: 23 additions & 18 deletions src/apps/auth/env.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import streamlit as st
import streamlit as st # type: ignore


def displayStreamlitSecrets(data, prefix=""):
for key, value in data.items():
full_key = f"{prefix}{key}"
if isinstance(value, dict):
st.divider()
st.markdown(f"**{full_key}/**")
displayStreamlitSecrets(value, prefix=full_key + "/")
else:
st.text_input(label=key, value=str(value), disabled=True, key=full_key)
for key, value in data.items():
full_key = f"{prefix}{key}"
if isinstance(value, dict):
st.divider()
st.markdown(f"**{full_key}/**")
displayStreamlitSecrets(value, prefix=full_key + "/")
else:
st.text_input(label=key, value=str(value),
disabled=True, key=full_key)


def env():
st.title("Environment Variables")
st.markdown(
"""
st.title("Environment Variables")
st.markdown(
"""
This page displays the environment variables used in the application.
The values are hidden for security reasons.
"""
)
if st.user.email == st.secrets["general"]["ADMIN_EMAIL"] and st.user.given_name == st.secrets["general"]["ADMIN_NAME"]:
st.success("You are logged in as an admin.", icon="✅")
displayStreamlitSecrets(st.secrets)
else:
st.warning("You are not authorized to view the environment variables.", icon="⚠️")
)
if st.user.email == st.secrets["general"]["ADMIN_EMAIL"] and st.user.given_name == st.secrets["general"]["ADMIN_NAME"]:
st.success("You are logged in as an admin.", icon="✅")
displayStreamlitSecrets(st.secrets)
else:
st.warning(
"You are not authorized to view the environment variables.", icon="⚠️")


env()
Loading