Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -74,3 +74,104 @@ if __name__ == "__main__":
|
|
74 |
st.title("🌌🚀 Transhuman Space Encyclopedia")
|
75 |
st.markdown("## Explore the universe of Transhuman Space through interactive storytelling and encyclopedic knowledge.🌠")
|
76 |
display_buttons_with_scores()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
st.title("🌌🚀 Transhuman Space Encyclopedia")
|
75 |
st.markdown("## Explore the universe of Transhuman Space through interactive storytelling and encyclopedic knowledge.🌠")
|
76 |
display_buttons_with_scores()
|
77 |
+
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
def fetch_wikipedia_summary(keyword):
|
84 |
+
# Placeholder function for fetching Wikipedia summaries
|
85 |
+
# In a real app, you might use requests to fetch from the Wikipedia API
|
86 |
+
return f"Summary for {keyword}. For more information, visit Wikipedia."
|
87 |
+
|
88 |
+
def create_search_url_youtube(keyword):
|
89 |
+
base_url = "https://www.youtube.com/results?search_query="
|
90 |
+
return base_url + keyword.replace(' ', '+')
|
91 |
+
|
92 |
+
def create_search_url_bing(keyword):
|
93 |
+
base_url = "https://www.bing.com/search?q="
|
94 |
+
return base_url + keyword.replace(' ', '+')
|
95 |
+
|
96 |
+
def create_search_url_wikipedia(keyword):
|
97 |
+
base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
|
98 |
+
return base_url + keyword.replace(' ', '+')
|
99 |
+
|
100 |
+
def create_search_url_google(keyword):
|
101 |
+
base_url = "https://www.google.com/search?q="
|
102 |
+
return base_url + keyword.replace(' ', '+')
|
103 |
+
|
104 |
+
def display_images_and_wikipedia_summaries():
|
105 |
+
st.title('Gallery with Related Stories')
|
106 |
+
image_files = [f for f in os.listdir('.') if f.endswith('.png')]
|
107 |
+
if not image_files:
|
108 |
+
st.write("No PNG images found in the current directory.")
|
109 |
+
return
|
110 |
+
|
111 |
+
for image_file in image_files:
|
112 |
+
image = Image.open(image_file)
|
113 |
+
st.image(image, caption=image_file, use_column_width=True)
|
114 |
+
|
115 |
+
keyword = image_file.split('.')[0] # Assumes keyword is the file name without extension
|
116 |
+
|
117 |
+
# Display Wikipedia and Google search links
|
118 |
+
wikipedia_url = create_search_url_wikipedia(keyword)
|
119 |
+
google_url = create_search_url_google(keyword)
|
120 |
+
youtube_url = create_search_url_youtube(keyword)
|
121 |
+
bing_url = create_search_url_bing(keyword)
|
122 |
+
|
123 |
+
links_md = f"""
|
124 |
+
[Wikipedia]({wikipedia_url}) |
|
125 |
+
[Google]({google_url}) |
|
126 |
+
[YouTube]({youtube_url}) |
|
127 |
+
[Bing]({bing_url})
|
128 |
+
"""
|
129 |
+
st.markdown(links_md)
|
130 |
+
|
131 |
+
display_images_and_wikipedia_summaries()
|
132 |
+
|
133 |
+
|
134 |
+
def get_all_query_params(key):
|
135 |
+
return st.query_params().get(key, [])
|
136 |
+
|
137 |
+
def clear_query_params():
|
138 |
+
st.query_params()
|
139 |
+
|
140 |
+
# Assuming the transhuman_glossary and other setup code remains the same
|
141 |
+
|
142 |
+
# Function to display content or image based on a query
|
143 |
+
def display_content_or_image(query):
|
144 |
+
# Check if the query matches any glossary term
|
145 |
+
for category, terms in transhuman_glossary.items():
|
146 |
+
for term in terms:
|
147 |
+
if query.lower() in term.lower():
|
148 |
+
st.subheader(f"Found in {category}:")
|
149 |
+
st.write(term)
|
150 |
+
return True # Return after finding and displaying the first match
|
151 |
+
|
152 |
+
# Check for an image match in a predefined directory (adjust path as needed)
|
153 |
+
image_dir = "images" # Example directory where images are stored
|
154 |
+
image_path = f"{image_dir}/{query}.png" # Construct image path with query
|
155 |
+
if os.path.exists(image_path):
|
156 |
+
st.image(image_path, caption=f"Image for {query}")
|
157 |
+
return True
|
158 |
+
|
159 |
+
# If no content or image is found
|
160 |
+
st.warning("No matching content or image found.")
|
161 |
+
return False
|
162 |
+
|
163 |
+
# Streamlit UI for displaying query parameters and handling actions
|
164 |
+
st.markdown("### Query Parameters - Navigate or Trigger Functionalities")
|
165 |
+
st.write("Current Query Parameters:", st.query_params())
|
166 |
+
|
167 |
+
if 'query' in st.query_params():
|
168 |
+
query = st.query_params()['query'][0] # Get the query parameter
|
169 |
+
# Display content or image based on the query
|
170 |
+
display_content_or_image(query)
|
171 |
+
|
172 |
+
# Add a clear query parameters button for convenience
|
173 |
+
if st.button("Clear Query Parameters"):
|
174 |
+
# This will clear the browser URL's query parameters
|
175 |
+
st.experimental_set_query_params()
|
176 |
+
st.experimental_rerun()
|
177 |
+
|