File size: 1,616 Bytes
a3280e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import streamlit as st
from azure.storage.blob import BlobServiceClient
import json
import os

connection_string = os.getenv("CONNECTION")
blob_service_client = BlobServiceClient.from_connection_string(connection_string)


def upload_blob(pdf_name, json_data, pdf_data):
    container_name = "jobdescriptions"
    json_blob_name = f"{pdf_name}_jsondata.json"
    pdf_blob_name = f"{pdf_name}.pdf"

    container_client = blob_service_client.get_container_client(container_name)

    json_blob_client = container_client.get_blob_client(json_blob_name)
    json_blob_client.upload_blob(json_data.encode('utf-8'), overwrite=True)

    pdf_blob_client = container_client.get_blob_client(pdf_blob_name)
    pdf_blob_client.upload_blob(pdf_data, overwrite=True)

    st.write('Data and PDF have been successfully uploaded to Azure Blob Storage.')


def main():
    st.title("PDF Upload and JobTitle and Email Input")

    uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])

    job_title = st.text_input("Enter the job title:")
    email = st.text_input("Enter the email:")

    if st.button("Submit") and uploaded_file:
        if job_title and email:
            data = {
                "jobTitle": job_title,
                "email": email
            }
            json_data = json.dumps(data, ensure_ascii=False)

            pdf_name = uploaded_file.name.split(".")[0]

            pdf_data = uploaded_file.read()

            upload_blob(pdf_name, json_data, pdf_data)
        else:
            st.write("Please fill out both fields and upload a PDF file.")


if __name__ == "__main__":
    main()