KONNECT / app.py
HuggyGuyJo01's picture
Create app.py
bf427c5 verified
import streamlit as st
import os
import zipfile
from pathlib import Path
import time
from backend_generator import generate_backend
from frontend_modifier import modify_dashboard, modify_chat_interface
from requirements_generator import generate_requirements
from file_processor import process_uploaded_files
def create_download_zip(backend_code, dashboard_html, chat_interface_html):
"""Create a ZIP file with all generated files"""
with zipfile.ZipFile("chatbot_pack.zip", "w") as zipf:
# Backend files
zipf.writestr("backend_gradio/app.py", backend_code)
zipf.writestr("backend_gradio/requirements.txt", generate_requirements("backend"))
# Dashboard files
zipf.writestr("dashboard_static/index.html", dashboard_html)
zipf.writestr("dashboard_static/requirements.txt", generate_requirements("dashboard"))
# Chat interface files
zipf.writestr("chat_interface_static/index.html", chat_interface_html)
zipf.writestr("chat_interface_static/requirements.txt", generate_requirements("chat"))
def main():
st.title("KONNECT - Chatbot Pack Generator")
# File upload section
st.header("1. Upload Files")
dashboard_file = st.file_uploader("Upload Dashboard HTML", type=['html'])
chat_interface_file = st.file_uploader("Upload Chat Interface HTML", type=['html'])
# URL input section
st.header("2. Enter HuggingFace Space URLs")
backend_url = st.text_input("Backend Gradio Space URL")
dashboard_url = st.text_input("Dashboard Static Space URL")
chat_interface_url = st.text_input("Chat Interface Static Space URL")
if st.button("Generate Chatbot Pack"):
if not all([dashboard_file, chat_interface_file, backend_url, dashboard_url, chat_interface_url]):
st.error("Please provide all required files and URLs")
return
progress_bar = st.progress(0)
status_text = st.empty()
try:
# Process uploaded files
status_text.text("Processing uploaded files...")
dashboard_content, chat_interface_content = process_uploaded_files(
dashboard_file, chat_interface_file
)
progress_bar.progress(20)
# Generate backend
status_text.text("Generating backend code...")
backend_code = generate_backend(
dashboard_content,
chat_interface_content,
backend_url
)
progress_bar.progress(40)
# Modify dashboard
status_text.text("Modifying dashboard...")
modified_dashboard = modify_dashboard(
dashboard_content,
backend_url
)
progress_bar.progress(60)
# Modify chat interface
status_text.text("Modifying chat interface...")
modified_chat_interface = modify_chat_interface(
chat_interface_content,
backend_url
)
progress_bar.progress(80)
# Create ZIP file
status_text.text("Creating ZIP file...")
create_download_zip(
backend_code,
modified_dashboard,
modified_chat_interface
)
progress_bar.progress(100)
# Provide download button
with open("chatbot_pack.zip", "rb") as fp:
st.download_button(
label="Download Chatbot Pack",
data=fp,
file_name="chatbot_pack.zip",
mime="application/zip"
)
status_text.text("Generation completed successfully!")
except Exception as e:
st.error(f"An error occurred: {str(e)}")
if __name__ == "__main__":
main()