import streamlit as st
import json
from bokeh.models.widgets import Div
import base64
# List of URLs
urls = [
"https://huggingface.co/spaces/awacke1/CB-GR-Chatbot-Blenderbot",
"https://huggingface.co/spaces/awacke1/TTS-STT-Blocks",
"https://huggingface.co/spaces/awacke1/Prompt-Refinery-Text-to-Image-Generation",
"https://huggingface.co/spaces/awacke1/Video-Summary",
"https://huggingface.co/spaces/awacke1/AI-MovieMaker-Comedy",
"https://huggingface.co/spaces/awacke1/ChatGPT-Memory-Chat-Story-Generator",
"https://huggingface.co/spaces/awacke1/CloneAnyVoice",
"https://huggingface.co/spaces/awacke1/ChatGPT-Streamlit-2",
"https://huggingface.co/spaces/awacke1/WikipediaUltimateAISearch",
"https://huggingface.co/spaces/awacke1/RLHF.Cognitive.Episodic.Semantic.Memory",
"https://huggingface.co/spaces/awacke1/Memory-Shared",
"https://huggingface.co/spaces/awacke1/VideoSwap",
"https://huggingface.co/spaces/awacke1/AI-Wikipedia-Search",
"https://huggingface.co/spaces/awacke1/AutoMLUsingStreamlit-Plotly",
"https://huggingface.co/spaces/awacke1/NLP-Lyric-Chorus-Image",
"https://huggingface.co/spaces/awacke1/OpenAssistant-Chatbot-FTW-Open-Source",
"https://huggingface.co/spaces/awacke1/ChatGPTStreamlit7",
"https://huggingface.co/spaces/awacke1/MultiPDF-QA-ChatGPT-Langchain",
"https://huggingface.co/spaces/awacke1/SOTA-Plan",
"https://huggingface.co/spaces/awacke1/AIandSmartTools",
"https://huggingface.co/spaces/awacke1/3DVirtualFood",
"https://huggingface.co/spaces/awacke1/Gradio-Gallery-Health-Medical-Icon-Sets",
"https://huggingface.co/spaces/awacke1/DatasetAnalyzer",
"https://huggingface.co/spaces/awacke1/PrompTart",
"https://huggingface.co/spaces/awacke1/sileod-deberta-v3-base-tasksource-nli",
"https://huggingface.co/spaces/awacke1/File-Memory-Operations-Human-Feedback-Gradio",
"https://huggingface.co/spaces/awacke1/Bloom.Big.Science.Continual.Generator",
"https://huggingface.co/spaces/awacke1/Ontology-Gradio",
"https://huggingface.co/spaces/awacke1/HTML5-Aframe-3dMap-Flight",
"https://huggingface.co/spaces/awacke1/Bloom.Generative.Writer",
"https://huggingface.co/spaces/awacke1/Voice-ChatGPT-Streamlit-12",
"https://huggingface.co/spaces/awacke1/HTML5-AR-VR",
"https://huggingface.co/spaces/awacke1/AnimationAI",
"https://huggingface.co/spaces/awacke1/GenerativeWordsandImages",
"https://huggingface.co/spaces/awacke1/AR-VR-IOT-Demo",
"https://huggingface.co/spaces/awacke1/ArtStyleFoodsandNutrition",
"https://huggingface.co/spaces/awacke1/CarePlanQnAWithContext",
"https://huggingface.co/spaces/awacke1/VideoSummaryYoutube3",
"https://huggingface.co/spaces/awacke1/AW-01ST-CSV-Dataset-Analyzer",
"https://huggingface.co/spaces/awacke1/Try.Playing.Learning.Sharing.On.This",
"https://huggingface.co/spaces/awacke1/google-flan-t5-base",
"https://huggingface.co/spaces/awacke1/PubMed-Parrot-Paraphraser-on-T5",
"https://huggingface.co/spaces/awacke1/Writing-Grammar-And-Paraphrase-w-Pegasus",
"https://huggingface.co/spaces/awacke1/runwayml-stable-diffusion-v1-5",
"https://huggingface.co/spaces/awacke1/DockerGoFlanT5",
"https://huggingface.co/spaces/awacke1/GradioContinualGenerator",
"https://huggingface.co/spaces/awacke1/StreamlitSuperPowerCheatSheet"
]
# Extract the last part of each URL (after the last '/') to serve as the name of the button
url_names = [url.split('/')[-1] for url in urls]
# Associate each URL with a relevant emoji based on keywords in its name
emoji_mapping = {
"Chatbot": "🤖",
"TTS": "🗣️",
"STT": "👂",
"Video": "🎥",
"MovieMaker": "🍿",
"ChatGPT": "💬",
"Voice": "🎙️",
"Wikipedia": "📖",
"Memory": "🧠",
"AI": "🧠",
"OpenAssistant": "🤝",
"3D": "🕶️",
"AR": "👓",
"VR": "🕶️",
"Animation": "🖌️",
"Dataset": "📊",
"Gradio": "📻",
"HTML5": "🌐",
"Writing": "✍️",
"Grammar": "🖋️",
"Paraphrase": "🔄",
"Streamlit": "🌠"
}
# Function to load the history of clicks from the text file
def load_history():
try:
with open("click_history.txt", "r") as f:
return json.load(f)
except FileNotFoundError:
return {url: 0 for url in urls}
# Function to save the updated history of clicks to the text file
def save_history(history):
with open("click_history.txt", "w") as f:
json.dump(history, f)
# Function to open the URL using the Bokeh model
def navigate_to_link(url):
js = "window.location.href = '{}'".format(url) # Current tab
html = '
'.format(js)
div = Div(text=html)
return div
# Function to create a base64 link and return the HTML string
def open_url(url, emoji, name):
link_name = f"{emoji} {name}"
b64 = base64.urlsafe_b64encode(url.encode()).decode() # some strings <-> bytes conversions necessary here
return f'{link_name}'
# Streamlit app
def streamlit_app():
# Load the history of clicks
history = load_history()
# Display the buttons for each URL
for url, name, emoji in zip(urls, url_names, emoji_mapping):
if st.button(f"{emoji} {name}"):
# Generate the base64 link and display it under the button
link_html = open_url(url, emoji, name)
st.markdown(link_html, unsafe_allow_html=True)
# Open the link using the navigate_to_link function
div = navigate_to_link(url)
st.bokeh_chart(div)
# Update the history of clicks
history[url] += 1
save_history(history)
# Display the number of times the URL was opened below its corresponding button
st.write(f"Clicked: {history[url]} times")
if __name__ == '__main__':
streamlit_app()