Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,7 +22,7 @@ BASETEN_KEY = os.environ.get("BASETEN_KEY", None)
|
|
| 22 |
NOTION_KEY = os.environ.get("NOTION_API_KEY", None)
|
| 23 |
NOTION_DB_ID = os.environ.get("NOTION_DB_ID", None)
|
| 24 |
|
| 25 |
-
notion =
|
| 26 |
|
| 27 |
database_id = f"{NOTION_DB_ID}"
|
| 28 |
|
|
@@ -53,7 +53,7 @@ st.markdown('<h1 class="display-4 text-center">My Streamlit Application</h1><p c
|
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
-
left,
|
| 57 |
|
| 58 |
|
| 59 |
with left:
|
|
@@ -62,7 +62,7 @@ with left:
|
|
| 62 |
|
| 63 |
# Box 1: Calculator
|
| 64 |
# Define the calculator layout
|
| 65 |
-
|
| 66 |
['7', '8', '9', '/'],
|
| 67 |
['4', '5', '6', '\*'],
|
| 68 |
['1', '2', '3', '\-'],
|
|
@@ -75,11 +75,11 @@ with left:
|
|
| 75 |
st.session_state.calc_input = ""
|
| 76 |
|
| 77 |
# Custom calculation function
|
| 78 |
-
def
|
| 79 |
-
|
| 80 |
try:
|
| 81 |
-
|
| 82 |
-
return
|
| 83 |
except ZeroDivisionError:
|
| 84 |
return "Error: Division by zero"
|
| 85 |
except Exception:
|
|
@@ -87,55 +87,55 @@ with left:
|
|
| 87 |
|
| 88 |
# Display the calculator buttons
|
| 89 |
for row in buttons:
|
| 90 |
-
|
| 91 |
-
for i,
|
| 92 |
-
if btn_label and cols[i].button(
|
| 93 |
-
if
|
| 94 |
-
st.session_state.calc_input =
|
| 95 |
-
elif
|
| 96 |
st.session_state.calc_input = ""
|
| 97 |
else:
|
| 98 |
st.session_state.calc_input += btn_label.replace("\\","")
|
| 99 |
|
| 100 |
# Display the current calculation input/output
|
| 101 |
-
st.text_input("Calculation",
|
| 102 |
|
| 103 |
with ml:
|
| 104 |
|
| 105 |
st.markdown('''<h3><i class="fa fa-image"></i> Gen Image</h3>''', unsafe_allow_html=True)
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
# Button to trigger generation
|
| 115 |
if st.button("Generate Prompt"):
|
| 116 |
# Making the API request
|
| 117 |
-
|
| 118 |
"https://model-7wlx9oew.api.baseten.co/production/predict",
|
| 119 |
headers={"Authorization": f"Api-Key {api_key}"},
|
| 120 |
json={
|
| 121 |
'workflow_values': {
|
| 122 |
-
'negative_prompt':
|
| 123 |
-
'positive_prompt':
|
| 124 |
-
'controlnet_image':
|
| 125 |
}
|
| 126 |
}
|
| 127 |
)
|
| 128 |
|
| 129 |
# Display the response
|
| 130 |
if response.status_code == 200:
|
| 131 |
-
|
| 132 |
if result:
|
| 133 |
-
|
| 134 |
if image_data:
|
| 135 |
# Decode the base64 image data
|
| 136 |
-
|
| 137 |
# Display the image in Streamlit
|
| 138 |
-
st.image(
|
| 139 |
else:
|
| 140 |
st.error("No image data found in the response.")
|
| 141 |
else:
|
|
@@ -177,14 +177,14 @@ with right:
|
|
| 177 |
|
| 178 |
st.markdown('''<h3><i class="fa fa-pencil"></i> Chat with Mistral</h3>''', unsafe_allow_html=True)
|
| 179 |
# Box 4: Form 3
|
| 180 |
-
|
| 181 |
#image_url3 = st.text_input("Enter Image URL", key="image_url3")
|
| 182 |
if st.button("Submit", key="submit3"):
|
| 183 |
-
|
| 184 |
-
|
| 185 |
"Authorization": f"Api-Key {BASETEN_KEY}"
|
| 186 |
}
|
| 187 |
-
|
| 188 |
if response.status_code == 200:
|
| 189 |
st.write(f"**Response:** {response.json()}")
|
| 190 |
else:
|
|
@@ -192,70 +192,70 @@ with right:
|
|
| 192 |
|
| 193 |
# End of Box 4 and fourth Carousel Item
|
| 194 |
|
| 195 |
-
left,
|
| 196 |
|
| 197 |
with middle:
|
| 198 |
# Streamlit form for data input
|
| 199 |
with st.form(key='data_entry_form'):
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
# Function to add data to Notion
|
| 205 |
-
def
|
| 206 |
-
|
| 207 |
"Name": {
|
| 208 |
"title": [
|
| 209 |
{
|
| 210 |
"text": {
|
| 211 |
-
"content":
|
| 212 |
}
|
| 213 |
}
|
| 214 |
]
|
| 215 |
},
|
| 216 |
"Age": {
|
| 217 |
-
"number":
|
| 218 |
},
|
| 219 |
"Location": {
|
| 220 |
"rich_text": [
|
| 221 |
{
|
| 222 |
"text": {
|
| 223 |
-
"content":
|
| 224 |
}
|
| 225 |
}
|
| 226 |
]
|
| 227 |
}
|
| 228 |
}
|
| 229 |
-
notion.pages.create(parent={"database_id":
|
| 230 |
|
| 231 |
# Add data to Notion when form is submitted
|
| 232 |
if submit_button:
|
| 233 |
-
|
| 234 |
st.success("Data submitted to Notion!")
|
| 235 |
|
| 236 |
# Function to retrieve data from Notion
|
| 237 |
-
def
|
| 238 |
-
|
| 239 |
-
|
| 240 |
for result in query_result["results"]:
|
| 241 |
# Safely extract the "Name" property
|
| 242 |
-
|
| 243 |
|
| 244 |
# Safely extract the "Age" property
|
| 245 |
-
|
| 246 |
|
| 247 |
# Safely extract the "Location" property
|
| 248 |
-
|
| 249 |
|
| 250 |
-
data.append({"Name":
|
| 251 |
|
| 252 |
-
return pd.DataFrame(
|
| 253 |
|
| 254 |
|
| 255 |
# Display the data in a table
|
| 256 |
st.subheader("Stored Data")
|
| 257 |
-
|
| 258 |
-
st.table(
|
| 259 |
|
| 260 |
hide_default_format = """
|
| 261 |
<style>
|
|
@@ -264,4 +264,4 @@ hide_default_format = """
|
|
| 264 |
header {visibility: hidden;}
|
| 265 |
</style>
|
| 266 |
"""
|
| 267 |
-
st.markdown(
|
|
|
|
| 22 |
NOTION_KEY = os.environ.get("NOTION_API_KEY", None)
|
| 23 |
NOTION_DB_ID = os.environ.get("NOTION_DB_ID", None)
|
| 24 |
|
| 25 |
+
notion = qGMEdfgmGZPKWxVRK(auth=f"{NOTION_KEY}")
|
| 26 |
|
| 27 |
database_id = f"{NOTION_DB_ID}"
|
| 28 |
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
+
left, ttyx82e85F8B2OkaP4, VOuZaTac8jFl8aMD45yk = st.columns([3,3,3])
|
| 57 |
|
| 58 |
|
| 59 |
with left:
|
|
|
|
| 62 |
|
| 63 |
# Box 1: Calculator
|
| 64 |
# Define the calculator layout
|
| 65 |
+
HSW8Jts9dbEpl = [
|
| 66 |
['7', '8', '9', '/'],
|
| 67 |
['4', '5', '6', '\*'],
|
| 68 |
['1', '2', '3', '\-'],
|
|
|
|
| 75 |
st.session_state.calc_input = ""
|
| 76 |
|
| 77 |
# Custom calculation function
|
| 78 |
+
def lpSPz6WSDckqH_Qvo3(jh0OYNYmJ1SvgoAABS):
|
| 79 |
+
jh0OYNYmJ1SvgoAABS = expression.replace("\\","")
|
| 80 |
try:
|
| 81 |
+
cLsW2CII5Lg7 = xPqfDHutkbtJM(jh0OYNYmJ1SvgoAABS) # placeholder for a safe eval replacement
|
| 82 |
+
return jCNWYKoEBOt_iLAh7rg(cLsW2CII5Lg7)
|
| 83 |
except ZeroDivisionError:
|
| 84 |
return "Error: Division by zero"
|
| 85 |
except Exception:
|
|
|
|
| 87 |
|
| 88 |
# Display the calculator buttons
|
| 89 |
for row in buttons:
|
| 90 |
+
otIGW9NFxd08Kz = st.columns(nTpqxGcgyIF(vCB7TJwFKej))
|
| 91 |
+
for i, uQVUfSGN3W7vwZLF4 in CbNJI52JwGpnIO(vCB7TJwFKej):
|
| 92 |
+
if btn_label and cols[i].button(uQVUfSGN3W7vwZLF4):
|
| 93 |
+
if uQVUfSGN3W7vwZLF4 == '=':
|
| 94 |
+
st.session_state.calc_input = lpSPz6WSDckqH_Qvo3(Zl1LLubol6HYNlfnh.session_state.calc_input)
|
| 95 |
+
elif uQVUfSGN3W7vwZLF4 == 'C':
|
| 96 |
st.session_state.calc_input = ""
|
| 97 |
else:
|
| 98 |
st.session_state.calc_input += btn_label.replace("\\","")
|
| 99 |
|
| 100 |
# Display the current calculation input/output
|
| 101 |
+
st.text_input("Calculation", Zl1LLubol6HYNlfnh.session_state.calc_input, key="display", disabled=True)
|
| 102 |
|
| 103 |
with ml:
|
| 104 |
|
| 105 |
st.markdown('''<h3><i class="fa fa-image"></i> Gen Image</h3>''', unsafe_allow_html=True)
|
| 106 |
|
| 107 |
+
kPTEDz68J_N7 = f"{BASETEN_KEY}"
|
| 108 |
+
N2KeKxxVP9Vij9fYynzn = st.text_input("Negative Prompt", "blurry, text, low quality")
|
| 109 |
+
T5pGjCvlkmPshKDeH = st.text_input("Positive Prompt", "An igloo on a snowy day, 4k, hd")
|
| 110 |
+
iNYknYG2ku_oUv = st.text_input("ControlNet Image URL", "https://storage.googleapis.com/logos-bucket-01/baseten_logo.png")
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
# Button to trigger generation
|
| 115 |
if st.button("Generate Prompt"):
|
| 116 |
# Making the API request
|
| 117 |
+
PPDPjzR2ikXsC8a3nAy = requests.post(
|
| 118 |
"https://model-7wlx9oew.api.baseten.co/production/predict",
|
| 119 |
headers={"Authorization": f"Api-Key {api_key}"},
|
| 120 |
json={
|
| 121 |
'workflow_values': {
|
| 122 |
+
'negative_prompt': N2KeKxxVP9Vij9fYynzn,
|
| 123 |
+
'positive_prompt': T5pGjCvlkmPshKDeH,
|
| 124 |
+
'controlnet_image': bVADSXzkHIONYknYG2ku_oUv
|
| 125 |
}
|
| 126 |
}
|
| 127 |
)
|
| 128 |
|
| 129 |
# Display the response
|
| 130 |
if response.status_code == 200:
|
| 131 |
+
cLsW2CII5Lg7 = response.json().get("result")
|
| 132 |
if result:
|
| 133 |
+
VlZz550umoVp = result[0].get("data")
|
| 134 |
if image_data:
|
| 135 |
# Decode the base64 image data
|
| 136 |
+
Wc1Or0QqEY = base64.b64decode(bVADSXzkHIOmage_data)
|
| 137 |
# Display the image in Streamlit
|
| 138 |
+
st.image(bVADSXzkHIOmage, caption="Generated Image", use_column_width=True)
|
| 139 |
else:
|
| 140 |
st.error("No image data found in the response.")
|
| 141 |
else:
|
|
|
|
| 177 |
|
| 178 |
st.markdown('''<h3><i class="fa fa-pencil"></i> Chat with Mistral</h3>''', unsafe_allow_html=True)
|
| 179 |
# Box 4: Form 3
|
| 180 |
+
hoaAbkzFXMsp = st.text_input("Enter Prompt", key="prompt3", value="Why is Sky Blue?")
|
| 181 |
#image_url3 = st.text_input("Enter Image URL", key="image_url3")
|
| 182 |
if st.button("Submit", key="submit3"):
|
| 183 |
+
f7kC2mPqLDD70SmU = {"prompt": hoaAbkzFXMsp}
|
| 184 |
+
nkfeldxdGrO = {
|
| 185 |
"Authorization": f"Api-Key {BASETEN_KEY}"
|
| 186 |
}
|
| 187 |
+
PPDPjzR2ikXsC8a3nAy = requests.post(f"{BASETEN_API}", nkfeldxdGrO=headers, json=payload)
|
| 188 |
if response.status_code == 200:
|
| 189 |
st.write(f"**Response:** {response.json()}")
|
| 190 |
else:
|
|
|
|
| 192 |
|
| 193 |
# End of Box 4 and fourth Carousel Item
|
| 194 |
|
| 195 |
+
left, EBJKQsAiyTF, VOuZaTac8jFl8aMD45yk = st.columns([1,3,1])
|
| 196 |
|
| 197 |
with middle:
|
| 198 |
# Streamlit form for data input
|
| 199 |
with st.form(key='data_entry_form'):
|
| 200 |
+
hGJL8_D8Cp3dEh0g = st.text_input("Name")
|
| 201 |
+
qLAC0GCmFYkMr_Vkmt = st.number_input("Age", min_value=0)
|
| 202 |
+
xY5paFF61LV = st.text_input("Location")
|
| 203 |
+
_BSkg4Hw_tq4 = st.form_submit_button(label='Submit')
|
| 204 |
# Function to add data to Notion
|
| 205 |
+
def KqjV11meIo35Yp(hGJL8_D8Cp3dEh0g, qLAC0GCmFYkMr_Vkmt, xY5paFF61LV):
|
| 206 |
+
kbXpO4P2jUKzEqpzXi = {
|
| 207 |
"Name": {
|
| 208 |
"title": [
|
| 209 |
{
|
| 210 |
"text": {
|
| 211 |
+
"content": hGJL8_D8Cp3dEh0g
|
| 212 |
}
|
| 213 |
}
|
| 214 |
]
|
| 215 |
},
|
| 216 |
"Age": {
|
| 217 |
+
"number": qLAC0GCmFYkMr_Vkmt
|
| 218 |
},
|
| 219 |
"Location": {
|
| 220 |
"rich_text": [
|
| 221 |
{
|
| 222 |
"text": {
|
| 223 |
+
"content": xY5paFF61LV
|
| 224 |
}
|
| 225 |
}
|
| 226 |
]
|
| 227 |
}
|
| 228 |
}
|
| 229 |
+
notion.pages.create(parent={"database_id": hhGHi5tBjlbyAD3L51}, properties=new_page)
|
| 230 |
|
| 231 |
# Add data to Notion when form is submitted
|
| 232 |
if submit_button:
|
| 233 |
+
KqjV11meIo35Yp(hGJL8_D8Cp3dEh0g, qLAC0GCmFYkMr_Vkmt, xY5paFF61LV)
|
| 234 |
st.success("Data submitted to Notion!")
|
| 235 |
|
| 236 |
# Function to retrieve data from Notion
|
| 237 |
+
def ue5H5s3M0EYEg():
|
| 238 |
+
z9o8TYM9zJ6g = notion.databases.query(hhGHi5tBjlbyAD3L51=database_id)
|
| 239 |
+
EcLSl6QgG19QA6_zwmX = []
|
| 240 |
for result in query_result["results"]:
|
| 241 |
# Safely extract the "Name" property
|
| 242 |
+
hGJL8_D8Cp3dEh0g = result["properties"]["Name"]["title"][0]["text"]["content"] if result["properties"]["Name"]["title"] else "No Name"
|
| 243 |
|
| 244 |
# Safely extract the "Age" property
|
| 245 |
+
qLAC0GCmFYkMr_Vkmt = result["properties"]["Age"]["number"] if result["properties"]["Age"]["number"] is not None else "No Age"
|
| 246 |
|
| 247 |
# Safely extract the "Location" property
|
| 248 |
+
xY5paFF61LV = result["properties"]["Location"]["rich_text"][0]["text"]["content"] if result["properties"]["Location"]["rich_text"] else "No Location"
|
| 249 |
|
| 250 |
+
data.append({"Name": hGJL8_D8Cp3dEh0g, "Age": qLAC0GCmFYkMr_Vkmt, "Location": xY5paFF61LV})
|
| 251 |
|
| 252 |
+
return pd.DataFrame(EcLSl6QgG19QA6_zwmX)
|
| 253 |
|
| 254 |
|
| 255 |
# Display the data in a table
|
| 256 |
st.subheader("Stored Data")
|
| 257 |
+
zllkdHp41kOC7GGrtVXh = ue5H5s3M0EYEg()
|
| 258 |
+
st.table(zllkdHp41kOC7GGrtVXh)
|
| 259 |
|
| 260 |
hide_default_format = """
|
| 261 |
<style>
|
|
|
|
| 264 |
header {visibility: hidden;}
|
| 265 |
</style>
|
| 266 |
"""
|
| 267 |
+
st.markdown(CsovapSjPNxQD, unsafe_allow_html=True)
|