File size: 3,995 Bytes
bf427c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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()