Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -37,6 +37,7 @@ class AIAgent:
|
|
37 |
self.name = name
|
38 |
self.description = description
|
39 |
self.skills = skills
|
|
|
40 |
|
41 |
def create_agent_prompt(self):
|
42 |
skills_str = '\n'.join([f"* {skill}" for skill in self.skills])
|
@@ -55,7 +56,26 @@ I am confident that I can leverage my expertise to assist you in developing and
|
|
55 |
return summary, next_step
|
56 |
|
57 |
def deploy_built_space_to_hf(self):
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
def process_input(input_text):
|
61 |
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium", tokenizer="microsoft/DialoGPT-medium")
|
@@ -95,6 +115,19 @@ def display_chat_history(chat_history):
|
|
95 |
def display_workspace_projects(workspace_projects):
|
96 |
return "\n".join([f"{p}: {details}" for p, details in workspace_projects.items()])
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
if __name__ == "__main__":
|
99 |
st.sidebar.title("Navigation")
|
100 |
app_mode = st.sidebar.selectbox("Choose the app mode", ["Home", "Terminal", "Explorer", "Code Editor", "Build & Deploy"])
|
@@ -165,6 +198,19 @@ if __name__ == "__main__":
|
|
165 |
st.markdown("## Congratulations! Successfully deployed Space π ##")
|
166 |
st.markdown("[Check out your new Space here](hf.co/" + repository.name + ")")
|
167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
# CSS for styling
|
169 |
st.markdown("""
|
170 |
<style>
|
|
|
37 |
self.name = name
|
38 |
self.description = description
|
39 |
self.skills = skills
|
40 |
+
self._hf_api = HfApi() # Initialize HfApi here
|
41 |
|
42 |
def create_agent_prompt(self):
|
43 |
skills_str = '\n'.join([f"* {skill}" for skill in self.skills])
|
|
|
56 |
return summary, next_step
|
57 |
|
58 |
def deploy_built_space_to_hf(self):
|
59 |
+
# Assuming you have a function that generates the space content
|
60 |
+
space_content = generate_space_content(project_name)
|
61 |
+
repository = self._hf_api.create_repo(
|
62 |
+
repo_id=project_name,
|
63 |
+
private=True,
|
64 |
+
token=hf_token,
|
65 |
+
exist_ok=True,
|
66 |
+
space_sdk="streamlit"
|
67 |
+
)
|
68 |
+
self._hf_api.upload_file(
|
69 |
+
path_or_fileobj=space_content,
|
70 |
+
path_in_repo="app.py",
|
71 |
+
repo_id=project_name,
|
72 |
+
repo_type="space",
|
73 |
+
token=hf_token
|
74 |
+
)
|
75 |
+
return repository
|
76 |
+
|
77 |
+
def has_valid_hf_token(self):
|
78 |
+
return self._hf_api.whoami(token=hf_token) is not None
|
79 |
|
80 |
def process_input(input_text):
|
81 |
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium", tokenizer="microsoft/DialoGPT-medium")
|
|
|
115 |
def display_workspace_projects(workspace_projects):
|
116 |
return "\n".join([f"{p}: {details}" for p, details in workspace_projects.items()])
|
117 |
|
118 |
+
def generate_space_content(project_name):
|
119 |
+
# Logic to generate the Streamlit app content based on project_name
|
120 |
+
# ... (This is where you'll need to implement the actual code generation)
|
121 |
+
return "import streamlit as st\nst.title('My Streamlit App')\nst.write('Hello, world!')"
|
122 |
+
|
123 |
+
# Function to display the AI Guide chat
|
124 |
+
def display_ai_guide_chat(chat_history):
|
125 |
+
st.markdown("<div class='chat-history'>", unsafe_allow_html=True)
|
126 |
+
for user_message, agent_message in chat_history:
|
127 |
+
st.markdown(f"<div class='chat-message user'>{user_message}</div>", unsafe_allow_html=True)
|
128 |
+
st.markdown(f"<div class='chat-message agent'>{agent_message}</div>", unsafe_allow_html=True)
|
129 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
130 |
+
|
131 |
if __name__ == "__main__":
|
132 |
st.sidebar.title("Navigation")
|
133 |
app_mode = st.sidebar.selectbox("Choose the app mode", ["Home", "Terminal", "Explorer", "Code Editor", "Build & Deploy"])
|
|
|
198 |
st.markdown("## Congratulations! Successfully deployed Space π ##")
|
199 |
st.markdown("[Check out your new Space here](hf.co/" + repository.name + ")")
|
200 |
|
201 |
+
# AI Guide Chat
|
202 |
+
if ai_guide_level != "No Assistance":
|
203 |
+
display_ai_guide_chat(st.session_state.chat_history)
|
204 |
+
# Add a text input for user to interact with the AI Guide
|
205 |
+
user_input = st.text_input("Ask the AI Guide a question:", key="user_input")
|
206 |
+
if st.button("Send"):
|
207 |
+
if user_input:
|
208 |
+
# Process the user's input and get a response from the AI Guide
|
209 |
+
agent_response = process_input(user_input)
|
210 |
+
st.session_state.chat_history.append((user_input, agent_response))
|
211 |
+
# Clear the user input field
|
212 |
+
st.session_state.user_input = ""
|
213 |
+
|
214 |
# CSS for styling
|
215 |
st.markdown("""
|
216 |
<style>
|