Spaces:
Running
Running
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() |