d3dname commited on
Commit
be8f63c
·
verified ·
1 Parent(s): 148fc87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -255
app.py CHANGED
@@ -1,267 +1,112 @@
1
- import streamlit as st
2
- import streamlit.components.v1 as components
3
  import requests
4
  import os
5
  import time
6
- import streamlit as st
7
  import base64
8
- from streamlit_mic_recorder import mic_recorder
9
- from notion_client import Client
10
- import pandas as pd
11
- MODEL_NAME = "drinktoomuchsax/whisper-small-hi"
12
- lang = "en"
13
-
14
- from threading import Thread
15
- os.environ["COQUI_TOS_AGREED"] = "1"
16
- os.environ["TRAINER_TELEMETRY"]= "0"
17
- # Constants
18
-
19
- HF_TOKEN = os.environ.get("HF_TOKEN", None)
20
- BASETEN_API = os.environ.get("BASETEN_API", None)
21
- 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 = qGMEdfgmGZPKWxVRK(auth=f"{NOTION_KEY}")
26
-
27
- database_id = f"{NOTION_DB_ID}"
28
-
29
- st.set_page_config(layout="wide")
30
- # Load custom CSS to integrate Bootstrap, Font Awesome, and Google Fonts
31
- st.markdown('''
32
- <link href="https://fonts.googleapis.com/css?family=Amatic+SC:400,700|Dosis:400,500,700&subset=latin,latin-ext" rel="stylesheet">
33
- <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">
34
- <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
35
- <style>
36
- body {
37
- font-family: 'Dosis', sans-serif;
38
- }
39
- h1, h2, h3 {
40
- font-family: 'Amatic SC', cursive;
41
- }
42
- .calculator button {
43
- width: 100%;
44
- padding: 20px;
45
- font-size: 24px;
46
- margin: 5px;
47
- }
48
- </style>
49
- ''', unsafe_allow_html=True)
50
-
51
- # Title Section
52
- st.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)
53
-
54
-
55
-
56
- left, ttyx82e85F8B2OkaP4, VOuZaTac8jFl8aMD45yk = st.columns([3,3,3])
57
-
58
-
59
- with left:
60
- # Carousel Structure
61
- st.markdown('''<h3><i class="fa fa-calculator"></i> Calculator</h3>''', unsafe_allow_html=True)
62
-
63
- # Box 1: Calculator
64
- # Define the calculator layout
65
- HSW8Jts9dbEpl = [
66
- ['7', '8', '9', '/'],
67
- ['4', '5', '6', '\*'],
68
- ['1', '2', '3', '\-'],
69
- ['C', '0', '.', '\+'],
70
- ['=']
71
- ]
72
-
73
- # To store the calculation input
74
- if 'calc_input' not in st.session_state:
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:
86
- return "Error"
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:
142
- st.error("No result found in the response.")
143
  else:
144
- st.error(f"Error: {response.status_code}, {response.text}")
145
-
146
-
147
- # with rl:
148
- # # End of Box 2 and second Carousel Item
149
- # st.markdown('''<h3><i class="fa fa-pencil"></i> Transcribe </h3>''', unsafe_allow_html=True)
150
-
151
- # # Box 3: Form 2
152
- # # Audio recording using mic_recorder
153
- # audio = mic_recorder(
154
- # start_prompt="Start recording",
155
- # stop_prompt="Stop recording",
156
- # just_once=False,
157
- # use_container_width=False,
158
- # callback=None,
159
- # key="mic_recorder"
160
- # )
161
-
162
- # #uploaded_file = st.file_uploader("Or upload an audio file", type=["mp3", "wav", "flac", "aac"])
163
- # if st.button("Transcribe"):
164
- # if audio and "bytes" in audio:
165
- # st.success("Recording detected. Transcribing your recording...")
166
- # with open("temp_recording.wav", "wb") as f:
167
- # f.write(audio["bytes"])
168
- # with st.spinner("Transcribing..."):
169
- # #transcription = transcribe("temp_recording.wav")
170
- # #need to send the data here
171
- # transcription = "Under Process"
172
- # print("")
173
- # st.text_area("Transcription", transcription, height=200)
174
- # else:
175
- # st.error("Please record audio or upload a file to transcribe.")
176
- 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
- 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:
191
- st.write("Failed to get a response")
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>
262
- #MainMenu {visibility: hidden; }
263
- footer {visibility: hidden;}
264
- header {visibility: hidden;}
265
- </style>
266
- """
267
- st.markdown(CsovapSjPNxQD, unsafe_allow_html=True)
 
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)