Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,112 +1,113 @@
|
|
| 1 |
-
import streamlit as
|
| 2 |
-
import streamlit.components.v1 as
|
| 3 |
-
import requests
|
| 4 |
-
import os
|
| 5 |
-
import time
|
| 6 |
-
import streamlit as
|
| 7 |
-
import base64
|
| 8 |
-
from
|
| 9 |
-
import
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
def
|
| 33 |
-
|
| 34 |
try:
|
| 35 |
-
|
| 36 |
-
return str(
|
| 37 |
except ZeroDivisionError:
|
| 38 |
return 'Error: Division by zero'
|
| 39 |
except Exception:
|
| 40 |
return 'Error'
|
| 41 |
-
for
|
| 42 |
-
|
| 43 |
-
for
|
| 44 |
-
if
|
| 45 |
-
if
|
| 46 |
-
|
| 47 |
-
elif
|
| 48 |
-
|
| 49 |
else:
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
with
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if
|
| 59 |
-
|
| 60 |
-
if
|
| 61 |
-
|
| 62 |
-
if
|
| 63 |
-
|
| 64 |
-
if
|
| 65 |
-
|
| 66 |
-
|
| 67 |
else:
|
| 68 |
-
|
| 69 |
else:
|
| 70 |
-
|
| 71 |
else:
|
| 72 |
-
|
| 73 |
-
with
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
if
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
if
|
| 81 |
-
|
| 82 |
else:
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
with
|
| 86 |
-
with
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
|
| 92 |
-
def
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
if
|
| 96 |
-
|
| 97 |
-
|
| 98 |
|
| 99 |
-
def
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
for
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
return
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
| 1 |
+
import streamlit as Xu1_s_YRKyqBPG3Rtk
|
| 2 |
+
import streamlit.components.v1 as FGLj98Tj6htb62
|
| 3 |
+
import requests as YKOZ_a8m0IIteB
|
| 4 |
+
import os as jaXQLEPpNYN7fZESeln
|
| 5 |
+
import time as lcPr1_RGGQ2u
|
| 6 |
+
import streamlit as ppc5pYLQY3Wy
|
| 7 |
+
import base64 as lZWuvN67Tq1Oajrh
|
| 8 |
+
from streamlit_mic_recorder import mic_recorder as CzoBrxqsRXK9KL_a
|
| 9 |
+
from notion_client import Client as NRO13Z5uLx6R_Si
|
| 10 |
+
import pandas as jCokbZAoxaSH
|
| 11 |
+
g6arVBaEwweAfW = 'drinktoomuchsax/whisper-small-hi'
|
| 12 |
+
hmKkYB0Vy36V_5 = 'en'
|
| 13 |
+
from threading import Thread as f3eMfSGlpjm
|
| 14 |
+
jaXQLEPpNYN7fZESeln.environ['COQUI_TOS_AGREED'] = '1'
|
| 15 |
+
jaXQLEPpNYN7fZESeln.environ['TRAINER_TELEMETRY'] = '0'
|
| 16 |
+
kOSXYC9sqLGQY1 = jaXQLEPpNYN7fZESeln.environ.get('HF_TOKEN', None)
|
| 17 |
+
YUdSktaTyqsUjKc7Tp = jaXQLEPpNYN7fZESeln.environ.get('BASETEN_API', None)
|
| 18 |
+
JZKqaWbvk3ke5VhmDPFa = jaXQLEPpNYN7fZESeln.environ.get('BASETEN_KEY', None)
|
| 19 |
+
vw0Pfd841JokahKHG = jaXQLEPpNYN7fZESeln.environ.get('NOTION_API_KEY', None)
|
| 20 |
+
x9in5mTsHJo = jaXQLEPpNYN7fZESeln.environ.get('NOTION_DB_ID', None)
|
| 21 |
+
wHoUZ_TWQ5 = NRO13Z5uLx6R_Si(auth=f'{vw0Pfd841JokahKHG}')
|
| 22 |
+
D2L9ohN562 = f'{x9in5mTsHJo}'
|
| 23 |
+
mUlXNhmWaZ4.set_page_config(layout='wide')
|
| 24 |
+
mUlXNhmWaZ4.markdown('\n <link href="https://fonts.googleapis.com/css?family=Amatic+SC:400,700|Dosis:400,500,700&subset=latin,latin-ext" rel="stylesheet">\n <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">\n <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">\n <style>\n body {\n font-family: \'Dosis\', sans-serif;\n }\n h1, h2, h3 {\n font-family: \'Amatic SC\', cursive;\n }\n .calculator button {\n width: 100%;\n padding: 20px;\n font-size: 24px;\n margin: 5px;\n }\n </style>\n', unsafe_allow_html=True)
|
| 25 |
+
mUlXNhmWaZ4.markdown('<h1 class="display-4 text-center">My Streamlit Application</h1><p class="lead text-center">Integrating Streamlit with Bootstrap Carousel</p>', unsafe_allow_html=True)
|
| 26 |
+
iZUZOs4rLk1ngHu, vdScuo8h42VU4Lc, zqq2ZomNZnpltfYQVG = mUlXNhmWaZ4.columns([3, 3, 3])
|
| 27 |
+
with iZUZOs4rLk1ngHu:
|
| 28 |
+
mUlXNhmWaZ4.markdown('<h3><i class="fa fa-calculator"></i> Calculator</h3>', unsafe_allow_html=True)
|
| 29 |
+
Tstven2mcRzUMKBBJ = [['7', '8', '9', '/'], ['4', '5', '6', '\\*'], ['1', '2', '3', '\\-'], ['C', '0', '.', '\\+'], ['=']]
|
| 30 |
+
if 'calc_input' not in mUlXNhmWaZ4.session_state:
|
| 31 |
+
mUlXNhmWaZ4.session_state.calc_input = ''
|
| 32 |
|
| 33 |
+
def J9MON3lkNKkvdDlLXQv1(VU6Ayctj5YBYuOgvGg0):
|
| 34 |
+
VU6Ayctj5YBYuOgvGg0 = VU6Ayctj5YBYuOgvGg0.replace('\\', '')
|
| 35 |
try:
|
| 36 |
+
athlnHoJS0oDHiuH = eval(VU6Ayctj5YBYuOgvGg0)
|
| 37 |
+
return str(athlnHoJS0oDHiuH)
|
| 38 |
except ZeroDivisionError:
|
| 39 |
return 'Error: Division by zero'
|
| 40 |
except Exception:
|
| 41 |
return 'Error'
|
| 42 |
+
for uMvxfOPTjWHGImIb in Tstven2mcRzUMKBBJ:
|
| 43 |
+
hfJXWtwczPea2YLmu = mUlXNhmWaZ4.columns(len(uMvxfOPTjWHGImIb))
|
| 44 |
+
for s_7ZN_0n1PrKfPIwpqJj, lNFeoCtqUXOy2c in enumerate(uMvxfOPTjWHGImIb):
|
| 45 |
+
if lNFeoCtqUXOy2c and hfJXWtwczPea2YLmu[s_7ZN_0n1PrKfPIwpqJj].button(lNFeoCtqUXOy2c):
|
| 46 |
+
if lNFeoCtqUXOy2c == '=':
|
| 47 |
+
mUlXNhmWaZ4.session_state.calc_input = J9MON3lkNKkvdDlLXQv1(mUlXNhmWaZ4.session_state.calc_input)
|
| 48 |
+
elif lNFeoCtqUXOy2c == 'C':
|
| 49 |
+
mUlXNhmWaZ4.session_state.calc_input = ''
|
| 50 |
else:
|
| 51 |
+
mUlXNhmWaZ4.session_state.calc_input += lNFeoCtqUXOy2c.replace('\\', '')
|
| 52 |
+
mUlXNhmWaZ4.text_input('Calculation', mUlXNhmWaZ4.session_state.calc_input, key='display', disabled=True)
|
| 53 |
+
with vdScuo8h42VU4Lc:
|
| 54 |
+
mUlXNhmWaZ4.markdown('<h3><i class="fa fa-image"></i> Gen Image</h3>', unsafe_allow_html=True)
|
| 55 |
+
lWipDlsimjcQkHxm = f'{JZKqaWbvk3ke5VhmDPFa}'
|
| 56 |
+
mUnZAiZho9J9HbpX = mUlXNhmWaZ4.text_input('Negative Prompt', 'blurry, text, low quality')
|
| 57 |
+
L8kiwV6VFlV = mUlXNhmWaZ4.text_input('Positive Prompt', 'An igloo on a snowy day, 4k, hd')
|
| 58 |
+
PnkIkPhMCssU5 = mUlXNhmWaZ4.text_input('ControlNet Image URL', 'https://storage.googleapis.com/logos-bucket-01/baseten_logo.png')
|
| 59 |
+
if mUlXNhmWaZ4.button('Generate Prompt'):
|
| 60 |
+
LUTP9A6agfaJg = YKOZ_a8m0IIteB.post('https://model-7wlx9oew.api.baseten.co/production/predict', headers={'Authorization': f'Api-Key {lWipDlsimjcQkHxm}'}, json={'workflow_values': {'negative_prompt': mUnZAiZho9J9HbpX, 'positive_prompt': L8kiwV6VFlV, 'controlnet_image': PnkIkPhMCssU5}})
|
| 61 |
+
if LUTP9A6agfaJg.status_code == 200:
|
| 62 |
+
athlnHoJS0oDHiuH = LUTP9A6agfaJg.json().get('result')
|
| 63 |
+
if athlnHoJS0oDHiuH:
|
| 64 |
+
GcwRbIkSJLQFwB_gQllf = athlnHoJS0oDHiuH[0].get('data')
|
| 65 |
+
if GcwRbIkSJLQFwB_gQllf:
|
| 66 |
+
e_wUUpvS8VU7tXTD2bU0 = lZWuvN67Tq1Oajrh.b64decode(GcwRbIkSJLQFwB_gQllf)
|
| 67 |
+
mUlXNhmWaZ4.image(e_wUUpvS8VU7tXTD2bU0, caption='Generated Image', use_column_width=True)
|
| 68 |
else:
|
| 69 |
+
mUlXNhmWaZ4.error('No image data found in the response.')
|
| 70 |
else:
|
| 71 |
+
mUlXNhmWaZ4.error('No result found in the response.')
|
| 72 |
else:
|
| 73 |
+
mUlXNhmWaZ4.error(f'Error: {LUTP9A6agfaJg.status_code}, {LUTP9A6agfaJg.text}')
|
| 74 |
+
with zqq2ZomNZnpltfYQVG:
|
| 75 |
+
mUlXNhmWaZ4.markdown('<h3><i class="fa fa-pencil"></i> Chat with Mistral</h3>', unsafe_allow_html=True)
|
| 76 |
+
GmV4HbtNJj = mUlXNhmWaZ4.text_input('Enter Prompt', key='prompt3', value='Why is Sky Blue?')
|
| 77 |
+
if mUlXNhmWaZ4.button('Submit', key='submit3'):
|
| 78 |
+
PymA0olldX4 = {'prompt': GmV4HbtNJj}
|
| 79 |
+
ECd6h8vVwG3X8i0 = {'Authorization': f'Api-Key {JZKqaWbvk3ke5VhmDPFa}'}
|
| 80 |
+
LUTP9A6agfaJg = YKOZ_a8m0IIteB.post(f'{YUdSktaTyqsUjKc7Tp}', headers=ECd6h8vVwG3X8i0, json=PymA0olldX4)
|
| 81 |
+
if LUTP9A6agfaJg.status_code == 200:
|
| 82 |
+
mUlXNhmWaZ4.write(f'**Response:** {LUTP9A6agfaJg.json()}')
|
| 83 |
else:
|
| 84 |
+
mUlXNhmWaZ4.write('Failed to get a response')
|
| 85 |
+
iZUZOs4rLk1ngHu, q0ArazFNq5gsvq, zqq2ZomNZnpltfYQVG = mUlXNhmWaZ4.columns([1, 3, 1])
|
| 86 |
+
with q0ArazFNq5gsvq:
|
| 87 |
+
with mUlXNhmWaZ4.form(key='data_entry_form'):
|
| 88 |
+
ZDkINyurNi = mUlXNhmWaZ4.text_input('Name')
|
| 89 |
+
TzvwY1x5YPa = mUlXNhmWaZ4.number_input('Age', min_value=0)
|
| 90 |
+
bKE8a3tiZnQYsW = mUlXNhmWaZ4.text_input('Location')
|
| 91 |
+
i4WtDCNwkaoqf75U = mUlXNhmWaZ4.form_submit_button(label='Submit')
|
| 92 |
|
| 93 |
+
def qUAmCp2ARaYU(ZDkINyurNi, TzvwY1x5YPa, bKE8a3tiZnQYsW):
|
| 94 |
+
pLOTJqAxCJUz = {'Name': {'title': [{'text': {'content': ZDkINyurNi}}]}, 'Age': {'number': TzvwY1x5YPa}, 'Location': {'rich_text': [{'text': {'content': bKE8a3tiZnQYsW}}]}}
|
| 95 |
+
wHoUZ_TWQ5.pages.create(parent={'database_id': D2L9ohN562}, properties=pLOTJqAxCJUz)
|
| 96 |
+
if i4WtDCNwkaoqf75U:
|
| 97 |
+
qUAmCp2ARaYU(ZDkINyurNi, TzvwY1x5YPa, bKE8a3tiZnQYsW)
|
| 98 |
+
mUlXNhmWaZ4.success('Data submitted to Notion!')
|
| 99 |
|
| 100 |
+
def sI9qDd8eeYG9r6w9j():
|
| 101 |
+
XVjjwr7OVLvdtQLHuZI = wHoUZ_TWQ5.databases.query(database_id=D2L9ohN562)
|
| 102 |
+
BDRUGpilyt = []
|
| 103 |
+
for athlnHoJS0oDHiuH in XVjjwr7OVLvdtQLHuZI['results']:
|
| 104 |
+
ZDkINyurNi = athlnHoJS0oDHiuH['properties']['Name']['title'][0]['text']['content'] if athlnHoJS0oDHiuH['properties']['Name']['title'] else 'No Name'
|
| 105 |
+
TzvwY1x5YPa = athlnHoJS0oDHiuH['properties']['Age']['number'] if athlnHoJS0oDHiuH['properties']['Age']['number'] is not None else 'No Age'
|
| 106 |
+
bKE8a3tiZnQYsW = athlnHoJS0oDHiuH['properties']['Location']['rich_text'][0]['text']['content'] if athlnHoJS0oDHiuH['properties']['Location']['rich_text'] else 'No Location'
|
| 107 |
+
BDRUGpilyt.append({'Name': ZDkINyurNi, 'Age': TzvwY1x5YPa, 'Location': bKE8a3tiZnQYsW})
|
| 108 |
+
return ATX4t7wg934Howfn.DataFrame(BDRUGpilyt)
|
| 109 |
+
mUlXNhmWaZ4.subheader('Stored Data')
|
| 110 |
+
gMoI0_JhjNG = sI9qDd8eeYG9r6w9j()
|
| 111 |
+
mUlXNhmWaZ4.table(gMoI0_JhjNG)
|
| 112 |
+
l1q117tznAWJz7 = '\n <style>\n #MainMenu {visibility: hidden; }\n footer {visibility: hidden;}\n header {visibility: hidden;}\n </style>\n '
|
| 113 |
+
mUlXNhmWaZ4.markdown(l1q117tznAWJz7, unsafe_allow_html=True)
|