d3dname commited on
Commit
468d0fa
·
verified ·
1 Parent(s): be8f63c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -99
app.py CHANGED
@@ -1,112 +1,113 @@
1
- import streamlit as XQhDDyy31Q
2
- import streamlit.components.v1 as YRfunIOZj4a
3
- import requests
4
- import os
5
- import time
6
- import streamlit as XQhDDyy31Q
7
- import base64
8
- from notion_client import Client as NYxNLLxHo8y3fvlA
9
- import pandas as DxKvlZwfuzR8wvP
10
- PfX0GMHlLslcoyyh1Ij = 'drinktoomuchsax/whisper-small-hi'
11
- fnTqln0TJgBS0M6jZ = 'en'
12
- from threading import Thread as fmOGZylJOq9w
13
- os.environ['COQUI_TOS_AGREED'] = '1'
14
- os.environ['TRAINER_TELEMETRY'] = '0'
15
- jAZtGw7fN2iyy = os.environ.get('HF_TOKEN', None)
16
- dezRUB5STvu9V = os.environ.get('BASETEN_API', None)
17
- B3GBXJAotmhx = os.environ.get('BASETEN_KEY', None)
18
- Nnh8WdtVyOKOYftc = os.environ.get('NOTION_API_KEY', None)
19
- pxSaUtMw0Lp5Pwt = os.environ.get('NOTION_DB_ID', None)
20
- G2N8A2McW18RkxP = NYxNLLxHo8y3fvlA(auth=f'{Nnh8WdtVyOKOYftc}')
21
- pzeL3JmsyR = f'{pxSaUtMw0Lp5Pwt}'
22
- XQhDDyy31Q.set_page_config(layout='wide')
23
- XQhDDyy31Q.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)
24
- XQhDDyy31Q.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)
25
- ymypjVvAasYDrsQ6ET, OzVNj4fgSPjs, ORaxFx2Hmm = XQhDDyy31Q.columns([3, 3, 3])
26
- with ymypjVvAasYDrsQ6ET:
27
- XQhDDyy31Q.markdown('<h3><i class="fa fa-calculator"></i> Calculator</h3>', unsafe_allow_html=True)
28
- wzlaohuTkgB = [['7', '8', '9', '/'], ['4', '5', '6', '\\*'], ['1', '2', '3', '\\-'], ['C', '0', '.', '\\+'], ['=']]
29
- if 'calc_input' not in XQhDDyy31Q.session_state:
30
- XQhDDyy31Q.session_state.calc_input = ''
 
31
 
32
- def k7YfuptnFfmoVbfy(expression):
33
- sB5lRljJ0D4ubL89z = sB5lRljJ0D4ubL89z.replace('\\', '')
34
  try:
35
- OZOcILw0hmo0fAG = eval(sB5lRljJ0D4ubL89z)
36
- return str(OZOcILw0hmo0fAG)
37
  except ZeroDivisionError:
38
  return 'Error: Division by zero'
39
  except Exception:
40
  return 'Error'
41
- for tdivWuSlIp8 in wzlaohuTkgB:
42
- ZVq0jH5BDLC9_66UcRq0 = XQhDDyy31Q.columns(len(tdivWuSlIp8))
43
- for a0MpybZzlQZDUPj, XWNDh1PFKe in enumerate(tdivWuSlIp8):
44
- if XWNDh1PFKe and ZVq0jH5BDLC9_66UcRq0[a0MpybZzlQZDUPj].button(XWNDh1PFKe):
45
- if XWNDh1PFKe == '=':
46
- XQhDDyy31Q.session_state.calc_input = k7YfuptnFfmoVbfy(XQhDDyy31Q.session_state.calc_input)
47
- elif XWNDh1PFKe == 'C':
48
- XQhDDyy31Q.session_state.calc_input = ''
49
  else:
50
- XQhDDyy31Q.session_state.calc_input += XWNDh1PFKe.replace('\\', '')
51
- XQhDDyy31Q.text_input('Calculation', XQhDDyy31Q.session_state.calc_input, key='display', disabled=True)
52
- with OzVNj4fgSPjs:
53
- XQhDDyy31Q.markdown('<h3><i class="fa fa-image"></i> Gen Image</h3>', unsafe_allow_html=True)
54
- m3YH0OhGWI0AwyySIewI = f'{B3GBXJAotmhx}'
55
- XNdkuz6oM12JN = XQhDDyy31Q.text_input('Negative Prompt', 'blurry, text, low quality')
56
- pJtI81p3ew = XQhDDyy31Q.text_input('Positive Prompt', 'An igloo on a snowy day, 4k, hd')
57
- ds13bnU7qKSBBK8G = XQhDDyy31Q.text_input('ControlNet Image URL', 'https://storage.googleapis.com/logos-bucket-01/baseten_logo.png')
58
- if XQhDDyy31Q.button('Generate Prompt'):
59
- hRnmRPs45lK = requests.post('https://model-7wlx9oew.api.baseten.co/production/predict', headers={'Authorization': f'Api-Key {m3YH0OhGWI0AwyySIewI}'}, json={'workflow_values': {'negative_prompt': XNdkuz6oM12JN, 'positive_prompt': pJtI81p3ew, 'controlnet_image': ds13bnU7qKSBBK8G}})
60
- if hRnmRPs45lK.status_code == 200:
61
- OZOcILw0hmo0fAG = hRnmRPs45lK.json().get('result')
62
- if OZOcILw0hmo0fAG:
63
- Pn4Uq0XlPXoxkd = OZOcILw0hmo0fAG[0].get('data')
64
- if Pn4Uq0XlPXoxkd:
65
- IHzZdRMxJN_5eQl = base64.b64decode(Pn4Uq0XlPXoxkd)
66
- XQhDDyy31Q.image(IHzZdRMxJN_5eQl, caption='Generated Image', use_column_width=True)
67
  else:
68
- XQhDDyy31Q.error('No image data found in the response.')
69
  else:
70
- XQhDDyy31Q.error('No result found in the response.')
71
  else:
72
- XQhDDyy31Q.error(f'Error: {hRnmRPs45lK.status_code}, {hRnmRPs45lK.text}')
73
- with ORaxFx2Hmm:
74
- XQhDDyy31Q.markdown('<h3><i class="fa fa-pencil"></i> Chat with Mistral</h3>', unsafe_allow_html=True)
75
- rN2iq58hS_pveOG = XQhDDyy31Q.text_input('Enter Prompt', key='prompt3', value='Why is Sky Blue?')
76
- if XQhDDyy31Q.button('Submit', key='submit3'):
77
- IWP72nW956BQ759OzG = {'prompt': rN2iq58hS_pveOG}
78
- pxXvTdG8bXXudwuvGVT3 = {'Authorization': f'Api-Key {B3GBXJAotmhx}'}
79
- hRnmRPs45lK = requests.post(f'{dezRUB5STvu9V}', headers=pxXvTdG8bXXudwuvGVT3, json=IWP72nW956BQ759OzG)
80
- if hRnmRPs45lK.status_code == 200:
81
- XQhDDyy31Q.write(f'**Response:** {hRnmRPs45lK.json()}')
82
  else:
83
- XQhDDyy31Q.write('Failed to get a response')
84
- ymypjVvAasYDrsQ6ET, nf8_MG_Umtm9CWVHoz9, ORaxFx2Hmm = XQhDDyy31Q.columns([1, 3, 1])
85
- with nf8_MG_Umtm9CWVHoz9:
86
- with XQhDDyy31Q.form(key='data_entry_form'):
87
- q40tcJeWRZBwin = XQhDDyy31Q.text_input('Name')
88
- MR94EBFaJpkVYxt0CZp = XQhDDyy31Q.number_input('Age', min_value=0)
89
- WvC2V3dPsQwnoCb = XQhDDyy31Q.text_input('Location')
90
- J_OnRhMhJiMemi_ = XQhDDyy31Q.form_submit_button(label='Submit')
91
 
92
- def YAsf9MMqkpY2zS7Rp(name, age, location):
93
- TYvRiD7fIp6eJ = {'Name': {'title': [{'text': {'content': q40tcJeWRZBwin}}]}, 'Age': {'number': MR94EBFaJpkVYxt0CZp}, 'Location': {'rich_text': [{'text': {'content': WvC2V3dPsQwnoCb}}]}}
94
- G2N8A2McW18RkxP.pages.create(parent={'database_id': pzeL3JmsyR}, properties=TYvRiD7fIp6eJ)
95
- if J_OnRhMhJiMemi_:
96
- YAsf9MMqkpY2zS7Rp(q40tcJeWRZBwin, MR94EBFaJpkVYxt0CZp, WvC2V3dPsQwnoCb)
97
- XQhDDyy31Q.success('Data submitted to Notion!')
98
 
99
- def wO634JKMnkQhzuUdve87():
100
- pgxfZXDbrz = G2N8A2McW18RkxP.databases.query(database_id=pzeL3JmsyR)
101
- OHtTlyebJzxETZiz5q9o = []
102
- for OZOcILw0hmo0fAG in pgxfZXDbrz['results']:
103
- q40tcJeWRZBwin = OZOcILw0hmo0fAG['properties']['Name']['title'][0]['text']['content'] if OZOcILw0hmo0fAG['properties']['Name']['title'] else 'No Name'
104
- MR94EBFaJpkVYxt0CZp = OZOcILw0hmo0fAG['properties']['Age']['number'] if OZOcILw0hmo0fAG['properties']['Age']['number'] is not None else 'No Age'
105
- WvC2V3dPsQwnoCb = OZOcILw0hmo0fAG['properties']['Location']['rich_text'][0]['text']['content'] if OZOcILw0hmo0fAG['properties']['Location']['rich_text'] else 'No Location'
106
- OHtTlyebJzxETZiz5q9o.append({'Name': q40tcJeWRZBwin, 'Age': MR94EBFaJpkVYxt0CZp, 'Location': WvC2V3dPsQwnoCb})
107
- return DxKvlZwfuzR8wvP.DataFrame(OHtTlyebJzxETZiz5q9o)
108
- XQhDDyy31Q.subheader('Stored Data')
109
- dShmKN7f96aNjIg9Fyqi = wO634JKMnkQhzuUdve87()
110
- XQhDDyy31Q.table(dShmKN7f96aNjIg9Fyqi)
111
- CHBmeLKxbX = '\n <style>\n #MainMenu {visibility: hidden; }\n footer {visibility: hidden;}\n header {visibility: hidden;}\n </style>\n '
112
- XQhDDyy31Q.markdown(CHBmeLKxbX, unsafe_allow_html=True)
 
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)