anuksharam/websitespace
0
1import streamlit as st2import leafmap.maplibregl as leafmap3import ibis4from ibis import _5import anthropic6import streamlit as st7import anthropic8 9# Anthropic client setup10client = anthropic.Anthropic(api_key='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')11 12# Streamlit titles13st.title("Website by Anuksha Ram")14st.color_picker("Current Mood [like a mood ring!]")15 16st.title("The Oracle")17 18st.text("Type your question into the -enter text- field below.")19st.text("It will replace the error message with your response!")20st.text("You can ask multiple questions!")21st.text("It will append new answers onto the end of the text block.")22st.text("This Chatbot is powered by ClaudeAI.")23 24# Initialize chat messages in session state25if "messages" not in st.session_state:26 st.session_state["messages"] = []27 28# Display previous messages29for message in st.session_state.messages:30 with st.chat_message(message["role"]):31 st.markdown(message["content"])32 33# Handle user input34if prompt := st.chat_input("What is up?"):35 # Add user message to session state36 st.session_state.messages.append({"role": "user", "content": prompt})37 with st.chat_message("user"):38 st.markdown(prompt)39 40 # Generate response from Anthropic41try:42 response = client.messages.create(43 model="claude-2.1",44 max_tokens=1000,45 messages=st.session_state.messages # Pass valid messages46 )47 st.write(response)48 assistant_message = response['completion']49 50 # Append the assistant's response to the session state51 st.session_state.messages.append({"role": "assistant", "content": assistant_message})52 # Display the assistant's message53 with st.chat_message("assistant"):54 st.markdown(assistant_message)55except Exception as e:56 st.error(f"An error occurred: {e}")57 58# City selection and mapping logic59city_name = st.text_input("Select a city", "Salt Lake City")60con = ibis.duckdb.connect()61city = (con62 .read_geo("/vsicurl/https://dsl.richmond.edu/panorama/redlining/static/mappinginequality.gpkg")63 .filter(_.city == city_name, _.residential)64 .execute()65)66 67# Render the map68m = leafmap.Map(style="positron")69m.add_gdf(city, "fill", paint={"fill-color": ["get", "fill"], "fill-opacity": 0.8})70m.to_streamlit()71 