Add1E commited on
Commit
a3280e8
·
1 Parent(s): 250c3af

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from azure.storage.blob import BlobServiceClient
3
+ import json
4
+ import os
5
+
6
+ connection_string = os.getenv("CONNECTION")
7
+ blob_service_client = BlobServiceClient.from_connection_string(connection_string)
8
+
9
+
10
+ def upload_blob(pdf_name, json_data, pdf_data):
11
+ container_name = "jobdescriptions"
12
+ json_blob_name = f"{pdf_name}_jsondata.json"
13
+ pdf_blob_name = f"{pdf_name}.pdf"
14
+
15
+ container_client = blob_service_client.get_container_client(container_name)
16
+
17
+ json_blob_client = container_client.get_blob_client(json_blob_name)
18
+ json_blob_client.upload_blob(json_data.encode('utf-8'), overwrite=True)
19
+
20
+ pdf_blob_client = container_client.get_blob_client(pdf_blob_name)
21
+ pdf_blob_client.upload_blob(pdf_data, overwrite=True)
22
+
23
+ st.write('Data and PDF have been successfully uploaded to Azure Blob Storage.')
24
+
25
+
26
+ def main():
27
+ st.title("PDF Upload and JobTitle and Email Input")
28
+
29
+ uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
30
+
31
+ job_title = st.text_input("Enter the job title:")
32
+ email = st.text_input("Enter the email:")
33
+
34
+ if st.button("Submit") and uploaded_file:
35
+ if job_title and email:
36
+ data = {
37
+ "jobTitle": job_title,
38
+ "email": email
39
+ }
40
+ json_data = json.dumps(data, ensure_ascii=False)
41
+
42
+ pdf_name = uploaded_file.name.split(".")[0]
43
+
44
+ pdf_data = uploaded_file.read()
45
+
46
+ upload_blob(pdf_name, json_data, pdf_data)
47
+ else:
48
+ st.write("Please fill out both fields and upload a PDF file.")
49
+
50
+
51
+ if __name__ == "__main__":
52
+ main()