Files changed (1) hide show
  1. app.py +105 -0
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import zipfile
4
+ from pathlib import Path
5
+ import time
6
+ from backend_generator import generate_backend
7
+ from frontend_modifier import modify_dashboard, modify_chat_interface
8
+ from requirements_generator import generate_requirements
9
+ from file_processor import process_uploaded_files
10
+
11
+ def create_download_zip(backend_code, dashboard_html, chat_interface_html):
12
+ """Create a ZIP file with all generated files"""
13
+ with zipfile.ZipFile("chatbot_pack.zip", "w") as zipf:
14
+ # Backend files
15
+ zipf.writestr("backend_gradio/app.py", backend_code)
16
+ zipf.writestr("backend_gradio/requirements.txt", generate_requirements("backend"))
17
+
18
+ # Dashboard files
19
+ zipf.writestr("dashboard_static/index.html", dashboard_html)
20
+ zipf.writestr("dashboard_static/requirements.txt", generate_requirements("dashboard"))
21
+
22
+ # Chat interface files
23
+ zipf.writestr("chat_interface_static/index.html", chat_interface_html)
24
+ zipf.writestr("chat_interface_static/requirements.txt", generate_requirements("chat"))
25
+
26
+ def main():
27
+ st.title("KONNECT - Chatbot Pack Generator")
28
+
29
+ # File upload section
30
+ st.header("1. Upload Files")
31
+ dashboard_file = st.file_uploader("Upload Dashboard HTML", type=['html'])
32
+ chat_interface_file = st.file_uploader("Upload Chat Interface HTML", type=['html'])
33
+
34
+ # URL input section
35
+ st.header("2. Enter HuggingFace Space URLs")
36
+ backend_url = st.text_input("Backend Gradio Space URL")
37
+ dashboard_url = st.text_input("Dashboard Static Space URL")
38
+ chat_interface_url = st.text_input("Chat Interface Static Space URL")
39
+
40
+ if st.button("Generate Chatbot Pack"):
41
+ if not all([dashboard_file, chat_interface_file, backend_url, dashboard_url, chat_interface_url]):
42
+ st.error("Please provide all required files and URLs")
43
+ return
44
+
45
+ progress_bar = st.progress(0)
46
+ status_text = st.empty()
47
+
48
+ try:
49
+ # Process uploaded files
50
+ status_text.text("Processing uploaded files...")
51
+ dashboard_content, chat_interface_content = process_uploaded_files(
52
+ dashboard_file, chat_interface_file
53
+ )
54
+ progress_bar.progress(20)
55
+
56
+ # Generate backend
57
+ status_text.text("Generating backend code...")
58
+ backend_code = generate_backend(
59
+ dashboard_content,
60
+ chat_interface_content,
61
+ backend_url
62
+ )
63
+ progress_bar.progress(40)
64
+
65
+ # Modify dashboard
66
+ status_text.text("Modifying dashboard...")
67
+ modified_dashboard = modify_dashboard(
68
+ dashboard_content,
69
+ backend_url
70
+ )
71
+ progress_bar.progress(60)
72
+
73
+ # Modify chat interface
74
+ status_text.text("Modifying chat interface...")
75
+ modified_chat_interface = modify_chat_interface(
76
+ chat_interface_content,
77
+ backend_url
78
+ )
79
+ progress_bar.progress(80)
80
+
81
+ # Create ZIP file
82
+ status_text.text("Creating ZIP file...")
83
+ create_download_zip(
84
+ backend_code,
85
+ modified_dashboard,
86
+ modified_chat_interface
87
+ )
88
+ progress_bar.progress(100)
89
+
90
+ # Provide download button
91
+ with open("chatbot_pack.zip", "rb") as fp:
92
+ st.download_button(
93
+ label="Download Chatbot Pack",
94
+ data=fp,
95
+ file_name="chatbot_pack.zip",
96
+ mime="application/zip"
97
+ )
98
+
99
+ status_text.text("Generation completed successfully!")
100
+
101
+ except Exception as e:
102
+ st.error(f"An error occurred: {str(e)}")
103
+
104
+ if __name__ == "__main__":
105
+ main()