Issue
The code:
#Libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
import fitz
import io
import streamlit as st
global path_input_0 #HERE ASSIGNMENTS-------------------------------
path_input_0=""
path_input_last=""
def login():
# interface codes for the login screen
path_input_0 =st.text_input("File Path:", "Please enter the path to the folder containing the Abstract_Account_Web_App.py file")
st.write(path_input_0)
global proceed
if st.button("Proceed"):
st.session_state["page"] = "main"
st.balloons()
st.experimental_rerun()
return path_input_0
def main():
# interface codes for the main screen
pathz=path_input_last+"/Bankomat Alışveriş Özeti.pdf"
st.write("path1:",pathz)
file_names = [r'%s' % pathz]
st.write(file_names)
if __name__=='__main__':
if "page" not in st.session_state:
st.session_state["page"] = "login"
if st.session_state["page"] == "login":
path_input_last=login()
st.write("last:",path_input_last)
elif st.session_state["page"] == "main":
st.balloons()
main()
Main screen: (First login screen, after main screen)
Hello friends, I’m trying to take the path from the login screen and use it on the main screen. The login function returns the path_input_0 from the user. But I can’t get this output and use it in the main function Pathz=path_input_last+“/Bankomat Alışveriş Özeti.pdf”
. Main function’s path_input_last comes as null.(“”) So it just prints path1 as /Bankomat Alışveriş Özeti.pdf. I don’t want that. The full file path is not coming.
Secondly, file_names = [r'%s' %pathz]
looks weird in the interface. My goal here was to take the file path as a variable and read it properly.
If I call login inside the main function again, I can get the variables I want, but this time the problem of calling the two interfaces together arises. It breaks this as my goal is to fetch the interfaces in order
How Can I solve these problems? Could you explain the solution?
Solution
def login():
# interface codes for the login screen
# (css,buttons,background,input area etc )
path_input_0 = st.text_input(
"File Path:",
"Please enter the path to the folder containing the Abstract_Account_Web_App.py file",
key="PATH_INPUT_LAST",
)
st.write(path_input_0)
global proceed
if st.button("Proceed"):
st.session_state["page"] = "main"
st.balloons()
st.experimental_rerun()
def main():
file0 = st.session_state["PATH_INPUT_LAST"]+"/Bankomat Alışveriş Özeti.csv"
st.write(file0)
if(os.path.exists(file0) and os.path.isfile(file0)):
os.remove(file0)
print("file was deleted as preprocessing")
else:
print("file was not found to delete")
# interface codes for the main screen
# (css,input,buttons etc.)
def set_texts(pdf_files:list):
print("starting to text process")
#This function reads pdf and gets "CRC-32" components as texts
for pdf_file in pdf_files:
with fitz.open(pdf_file) as doc:
text = ""
for page in doc:
new_text = page.get_text()
text += new_text
return text
pathz = st.session_state["PATH_INPUT_LAST"] + "/Bankomat Alışveriş Özeti.pdf"
st.write("path1:", pathz)
file_names = r'%s' % pathz
st.write(file_names)
set_texts([file_names])
if __name__ == "__main__":
if "page" not in st.session_state:
st.session_state["page"] = "login"
if st.session_state["page"] == "login":
login()
elif st.session_state["page"] == "main":
st.balloons()
main()
Answered By - murat taşçı
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.