Spaces:
Running
Running
Commit
•
097ecdb
1
Parent(s):
c6cc621
Update app.py
Browse files
app.py
CHANGED
@@ -3,12 +3,20 @@ import os
|
|
3 |
import subprocess
|
4 |
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
5 |
import black
|
6 |
-
from pylint import lint
|
7 |
from io import StringIO
|
8 |
import sys
|
9 |
|
10 |
PROJECT_ROOT = "projects"
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Define functions for each feature
|
13 |
|
14 |
# 1. Chat Interface
|
@@ -90,9 +98,7 @@ def code_editor_interface(code):
|
|
90 |
# Lint code using pylint
|
91 |
try:
|
92 |
pylint_output = StringIO()
|
93 |
-
|
94 |
-
lint.Run(["--from-stdin"], stdin=StringIO(formatted_code))
|
95 |
-
sys.stdout = sys.__stdout__
|
96 |
lint_message = pylint_output.getvalue()
|
97 |
except Exception as e:
|
98 |
lint_message = f"Pylint error: {e}"
|
@@ -118,6 +124,7 @@ def workspace_interface(project_name):
|
|
118 |
with open(requirements_path, "w") as req_file:
|
119 |
req_file.write("") # Initialize an empty requirements.txt file
|
120 |
status = f'Project "{project_name}" created successfully.'
|
|
|
121 |
except FileExistsError:
|
122 |
status = f'Project "{project_name}" already exists.'
|
123 |
return status
|
@@ -140,6 +147,7 @@ def add_code_to_workspace(project_name, code, file_name):
|
|
140 |
with open(file_path, "w") as code_file:
|
141 |
code_file.write(code)
|
142 |
status = f'File "{file_name}" added to project "{project_name}" successfully.'
|
|
|
143 |
except Exception as e:
|
144 |
status = f"Error: {e}"
|
145 |
return status
|
@@ -149,7 +157,6 @@ def add_code_to_workspace(project_name, code, file_name):
|
|
149 |
|
150 |
# Define custom AI-powered tools using Hugging Face models
|
151 |
|
152 |
-
|
153 |
# Example: Text summarization tool
|
154 |
def summarize_text(text):
|
155 |
"""Summarizes a given text using a Hugging Face model.
|
@@ -281,6 +288,7 @@ if app_mode == "Tool Box":
|
|
281 |
chat_input = st.text_area("Enter your message:")
|
282 |
if st.button("Send"):
|
283 |
chat_response = chat_interface(chat_input)
|
|
|
284 |
st.write(f"CodeCraft: {chat_response}")
|
285 |
|
286 |
# Terminal Interface
|
@@ -288,6 +296,7 @@ if app_mode == "Tool Box":
|
|
288 |
terminal_input = st.text_input("Enter a command:")
|
289 |
if st.button("Run"):
|
290 |
terminal_output = terminal_interface(terminal_input)
|
|
|
291 |
st.code(terminal_output, language="bash")
|
292 |
|
293 |
# Code Editor Interface
|
@@ -358,4 +367,24 @@ elif app_mode == "Workspace Chat App":
|
|
358 |
chat_input = st.text_area("Enter your message for guidance:")
|
359 |
if st.button("Get Guidance"):
|
360 |
chat_response = chat_interface(chat_input)
|
361 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import subprocess
|
4 |
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
5 |
import black
|
6 |
+
from pylint import epylint as lint
|
7 |
from io import StringIO
|
8 |
import sys
|
9 |
|
10 |
PROJECT_ROOT = "projects"
|
11 |
|
12 |
+
# Global state to manage communication between Tool Box and Workspace Chat App
|
13 |
+
if 'chat_history' not in st.session_state:
|
14 |
+
st.session_state.chat_history = []
|
15 |
+
if 'terminal_history' not in st.session_state:
|
16 |
+
st.session_state.terminal_history = []
|
17 |
+
if 'workspace_projects' not in st.session_state:
|
18 |
+
st.session_state.workspace_projects = {}
|
19 |
+
|
20 |
# Define functions for each feature
|
21 |
|
22 |
# 1. Chat Interface
|
|
|
98 |
# Lint code using pylint
|
99 |
try:
|
100 |
pylint_output = StringIO()
|
101 |
+
lint.py_run(f"--from-stdin", return_std=True, stdin=StringIO(formatted_code))
|
|
|
|
|
102 |
lint_message = pylint_output.getvalue()
|
103 |
except Exception as e:
|
104 |
lint_message = f"Pylint error: {e}"
|
|
|
124 |
with open(requirements_path, "w") as req_file:
|
125 |
req_file.write("") # Initialize an empty requirements.txt file
|
126 |
status = f'Project "{project_name}" created successfully.'
|
127 |
+
st.session_state.workspace_projects[project_name] = {'files': []}
|
128 |
except FileExistsError:
|
129 |
status = f'Project "{project_name}" already exists.'
|
130 |
return status
|
|
|
147 |
with open(file_path, "w") as code_file:
|
148 |
code_file.write(code)
|
149 |
status = f'File "{file_name}" added to project "{project_name}" successfully.'
|
150 |
+
st.session_state.workspace_projects[project_name]['files'].append(file_name)
|
151 |
except Exception as e:
|
152 |
status = f"Error: {e}"
|
153 |
return status
|
|
|
157 |
|
158 |
# Define custom AI-powered tools using Hugging Face models
|
159 |
|
|
|
160 |
# Example: Text summarization tool
|
161 |
def summarize_text(text):
|
162 |
"""Summarizes a given text using a Hugging Face model.
|
|
|
288 |
chat_input = st.text_area("Enter your message:")
|
289 |
if st.button("Send"):
|
290 |
chat_response = chat_interface(chat_input)
|
291 |
+
st.session_state.chat_history.append((chat_input, chat_response))
|
292 |
st.write(f"CodeCraft: {chat_response}")
|
293 |
|
294 |
# Terminal Interface
|
|
|
296 |
terminal_input = st.text_input("Enter a command:")
|
297 |
if st.button("Run"):
|
298 |
terminal_output = terminal_interface(terminal_input)
|
299 |
+
st.session_state.terminal_history.append((terminal_input, terminal_output))
|
300 |
st.code(terminal_output, language="bash")
|
301 |
|
302 |
# Code Editor Interface
|
|
|
367 |
chat_input = st.text_area("Enter your message for guidance:")
|
368 |
if st.button("Get Guidance"):
|
369 |
chat_response = chat_interface(chat_input)
|
370 |
+
st.session_state.chat_history.append((chat_input, chat_response))
|
371 |
+
st.write(f"CodeCraft: {chat_response}")
|
372 |
+
|
373 |
+
# Display Chat History
|
374 |
+
st.subheader("Chat History")
|
375 |
+
for user_input, response in st.session_state.chat_history:
|
376 |
+
st.write(f"User: {user_input}")
|
377 |
+
st.write(f"CodeCraft: {response}")
|
378 |
+
|
379 |
+
# Display Terminal History
|
380 |
+
st.subheader("Terminal History")
|
381 |
+
for command, output in st.session_state.terminal_history:
|
382 |
+
st.write(f"Command: {command}")
|
383 |
+
st.code(output, language="bash")
|
384 |
+
|
385 |
+
# Display Projects and Files
|
386 |
+
st.subheader("Workspace Projects")
|
387 |
+
for project, details in st.session_state.workspace_projects.items():
|
388 |
+
st.write(f"Project: {project}")
|
389 |
+
for file in details['files']:
|
390 |
+
st.write(f" - {file}")
|