Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import base64 | |
import datetime | |
def main(): | |
st.title("Friends in Flats Wohnungs Setup Assistant") | |
st.write("""Bitte Schicken sie uns das excel file nach ihrer überprufung an [email protected] zum verarbeiten. | |
Bei Fragen uns bitte Kontaktieren auf : +43720882394""") | |
address = st.text_input("Address") | |
num_rooms = st.number_input("Number of Rooms", min_value=1, step=1) | |
room_details = [] | |
for i in range(num_rooms): | |
room_type = st.text_input(f"Zimmer {i+1} Typ") | |
num_amenities = st.number_input(f"Nummer von Zimmern in der Wohnung: {i+1}", min_value=0, step=1) | |
amenities = [] | |
for j in range(num_amenities): | |
amenity_serial = st.text_input(f"Austattung {j+1} Serien Nummer") | |
amenity_type = st.text_input(f"Austattung {j+1} Typ") | |
amenity_details = st.text_input(f"Austattung {j+1} Details") | |
amenity_image = st.file_uploader(f"Austattung {j+1} Foto", type=["png", "jpg", "jpeg"], accept_multiple_files=False, key=f"amenity_{j+1}_image") | |
if amenity_image is not None: | |
encoded_image = base64.b64encode(amenity_image.read()).decode("utf-8") | |
else: | |
encoded_image = "" | |
amenities.append({ | |
"Serial Number": amenity_serial, | |
"Type": amenity_type, | |
"Image": encoded_image, | |
"Details":amenity_details | |
}) | |
room_details.append({ | |
"Room Type": room_type, | |
"Amenities": amenities | |
}) | |
if st.button("Save as Excel"): | |
file_path = st.file_uploader("Wo wollen sie die excel datei Speichern", type=["xlsx"], accept_multiple_files=False, key="excel_file_path") | |
if file_path is not None: | |
save_as_excel(file_path, address, room_details) | |
def save_as_excel(file_path, address, room_details): | |
current_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S") | |
data = { | |
"Address": [address], | |
"Room Type": [], | |
"Amenity Serial Number": [], | |
"Amenity Type": [], | |
"Amenity Image": [], | |
"Amenity Details":[] | |
} | |
for room in room_details: | |
room_type = room["Room Type"] | |
for amenity in room["Amenities"]: | |
data["Room Type"].append(room_type) | |
data["Amenity Serial Number"].append(amenity["Serial Number"]) | |
data["Amenity Type"].append(amenity["Type"]) | |
data["Amenity Image"].append(amenity["Image"]) | |
data["Amenity Details"].append(amenity["Details"]) | |
df = pd.DataFrame(data) | |
df.to_excel(file_path, index=False) | |
if __name__ == "__main__": | |
main() |