How to write locally from a streamlit server in ann internal nerwork

Hello All,

Thank you for supporting me.

I have a streamlit application that takes some input fields and then write a word document and transform a pdf. When I run it locally, works perfect.

Now I am launching the app for being viewed in a network using:

streamlit run generador.py --server.address 192.168.2.79 --server. Port 8501

other computer can access to the program via http://192.168.2.79:8501 (this server is my computer)

but when they fill the data and try to write de doc and pdf, both documents are saving in my computer, not in the computer n the network.

I’m using this part of the code for writing the document

        user_profile = os.environ['USERPROFILE']
        descarga = os.path.join(user_profile, 'Downloads')
        plantilla = f"NDA - {empresa}.docx"
        output_path = os.path.join(descarga,plantilla)
        doc.save(output_path)
        convert(output_path)

I thought that USERPROFILE (in my case is “c:\users\LMM”) will work in the other computer getting the local path, but always the file is generated in mine.

Thanks in advance

Hi @LMM ,

It appears that the issue is related to the usage of the USERPROFILE environment variable, which points to your local user profile directory. When you run your Streamlit app on another computer through the network, it will still reference the USERPROFILE of the machine where the Streamlit app is running.

To make the document saving location dynamic and based on the user’s machine, you can use the os module to get the user’s home directory. Here’s an example of how you can modify your code:

import os

# Get the user's home directory
user_home = os.path.expanduser("~")

# Define the path where you want to save the document
descarga = os.path.join(user_home, 'Downloads')

# Rest of your code
plantilla = f"NDA - {empresa}.docx"
output_path = os.path.join(descarga, plantilla)
doc.save(output_path)
convert(output_path)

By using os.path.expanduser("~"), you will get the user’s home directory path dynamically based on the user’s machine, allowing the document to be saved in their local Downloads directory rather than your own.

Thank you @sai_krishna1 !

I copy your suggestion and I’m afraid that doesn’t work.

It keeps to write in my machine

Best
Luis