Spaces:
Running
Running
acecalisto3
commited on
Commit
•
d754f21
1
Parent(s):
82813f8
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,24 @@
|
|
1 |
-
import
|
2 |
import os
|
3 |
import subprocess
|
4 |
import random
|
5 |
import string
|
6 |
from huggingface_hub import cached_download, hf_hub_url
|
7 |
from transformers import pipeline
|
|
|
|
|
8 |
|
9 |
# Define functions for each feature
|
10 |
|
11 |
# 1. Chat Interface
|
12 |
-
def chat_interface(input_text
|
13 |
"""Handles user input in the chat interface.
|
14 |
|
15 |
Args:
|
16 |
input_text: User's input text.
|
17 |
-
history: Chat history.
|
18 |
|
19 |
Returns:
|
20 |
-
|
21 |
"""
|
22 |
# Load the appropriate language model from Hugging Face
|
23 |
model_name = 'google/flan-t5-xl' # Choose a suitable model
|
@@ -27,21 +28,17 @@ def chat_interface(input_text, history):
|
|
27 |
|
28 |
# Generate chatbot response
|
29 |
response = generator(input_text, max_length=50, num_return_sequences=1, do_sample=True)[0]['generated_text']
|
30 |
-
|
31 |
-
# Update chat history
|
32 |
-
history.append((input_text, response))
|
33 |
-
return history, response
|
34 |
|
35 |
# 2. Terminal
|
36 |
-
def terminal_interface(command
|
37 |
"""Executes commands in the terminal.
|
38 |
|
39 |
Args:
|
40 |
command: User's command.
|
41 |
-
history: Terminal command history.
|
42 |
|
43 |
Returns:
|
44 |
-
|
45 |
"""
|
46 |
# Execute command
|
47 |
try:
|
@@ -49,10 +46,7 @@ def terminal_interface(command, history):
|
|
49 |
output = process.stdout
|
50 |
except Exception as e:
|
51 |
output = f'Error: {e}'
|
52 |
-
|
53 |
-
# Update command history
|
54 |
-
history.append((command, output))
|
55 |
-
return history, output
|
56 |
|
57 |
# 3. Code Editor
|
58 |
def code_editor_interface(code):
|
@@ -64,22 +58,31 @@ def code_editor_interface(code):
|
|
64 |
Returns:
|
65 |
Formatted and linted code.
|
66 |
"""
|
67 |
-
#
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
# 4. Workspace
|
74 |
-
def workspace_interface(project_name
|
75 |
"""Manages projects, files, and resources in the workspace.
|
76 |
|
77 |
Args:
|
78 |
project_name: Name of the new project.
|
79 |
-
history: Workspace history.
|
80 |
|
81 |
Returns:
|
82 |
-
|
83 |
"""
|
84 |
# Create project directory
|
85 |
try:
|
@@ -87,10 +90,7 @@ def workspace_interface(project_name, history):
|
|
87 |
status = f'Project \"{project_name}\" created successfully.'
|
88 |
except FileExistsError:
|
89 |
status = f'Project \"{project_name}\" already exists.'
|
90 |
-
|
91 |
-
# Update workspace history
|
92 |
-
history.append((project_name, status))
|
93 |
-
return history, status
|
94 |
|
95 |
# 5. AI-Infused Tools
|
96 |
|
@@ -110,56 +110,41 @@ def summarize_text(text):
|
|
110 |
summary = summarizer(text, max_length=100, min_length=30)[0]['summary_text']
|
111 |
return summary
|
112 |
|
113 |
-
#
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
# Workspace interface
|
152 |
-
workspace_history = gr.State([]) # Initialize workspace history
|
153 |
-
workspace_input = gr.Textbox(label="Project Name", lines=1)
|
154 |
-
workspace_output = gr.Textbox(label="Workspace Data", lines=5)
|
155 |
-
workspace_button = gr.Button(value="Create Project")
|
156 |
-
workspace_button.click(workspace_interface, inputs=[workspace_input, workspace_history], outputs=[workspace_history, workspace_output])
|
157 |
-
|
158 |
-
# AI-Infused Tools
|
159 |
-
text_input = gr.Textbox(label="Enter text to summarize")
|
160 |
-
summary_output = gr.Textbox(label="Summarized Text")
|
161 |
-
summarize_button = gr.Button(value="Summarize")
|
162 |
-
summarize_button.click(summarize_text, inputs=text_input, outputs=summary_output)
|
163 |
-
|
164 |
-
# Launch Gradio app
|
165 |
-
demo.launch(share=True, server_name='0.0.0.0')
|
|
|
1 |
+
import streamlit as st
|
2 |
import os
|
3 |
import subprocess
|
4 |
import random
|
5 |
import string
|
6 |
from huggingface_hub import cached_download, hf_hub_url
|
7 |
from transformers import pipeline
|
8 |
+
import black
|
9 |
+
import pylint
|
10 |
|
11 |
# Define functions for each feature
|
12 |
|
13 |
# 1. Chat Interface
|
14 |
+
def chat_interface(input_text):
|
15 |
"""Handles user input in the chat interface.
|
16 |
|
17 |
Args:
|
18 |
input_text: User's input text.
|
|
|
19 |
|
20 |
Returns:
|
21 |
+
The chatbot's response.
|
22 |
"""
|
23 |
# Load the appropriate language model from Hugging Face
|
24 |
model_name = 'google/flan-t5-xl' # Choose a suitable model
|
|
|
28 |
|
29 |
# Generate chatbot response
|
30 |
response = generator(input_text, max_length=50, num_return_sequences=1, do_sample=True)[0]['generated_text']
|
31 |
+
return response
|
|
|
|
|
|
|
32 |
|
33 |
# 2. Terminal
|
34 |
+
def terminal_interface(command):
|
35 |
"""Executes commands in the terminal.
|
36 |
|
37 |
Args:
|
38 |
command: User's command.
|
|
|
39 |
|
40 |
Returns:
|
41 |
+
The terminal output.
|
42 |
"""
|
43 |
# Execute command
|
44 |
try:
|
|
|
46 |
output = process.stdout
|
47 |
except Exception as e:
|
48 |
output = f'Error: {e}'
|
49 |
+
return output
|
|
|
|
|
|
|
50 |
|
51 |
# 3. Code Editor
|
52 |
def code_editor_interface(code):
|
|
|
58 |
Returns:
|
59 |
Formatted and linted code.
|
60 |
"""
|
61 |
+
# Format code using black
|
62 |
+
try:
|
63 |
+
formatted_code = black.format_str(code, mode=black.FileMode())
|
64 |
+
except black.InvalidInput:
|
65 |
+
formatted_code = code # Keep original code if formatting fails
|
66 |
+
|
67 |
+
# Lint code using pylint
|
68 |
+
try:
|
69 |
+
pylint_output = pylint.run(formatted_code, output=None)
|
70 |
+
lint_results = pylint_output.linter.stats.get('global_note', 0)
|
71 |
+
lint_message = f"Pylint score: {lint_results:.2f}"
|
72 |
+
except Exception as e:
|
73 |
+
lint_message = f"Pylint error: {e}"
|
74 |
+
|
75 |
+
return formatted_code, lint_message
|
76 |
|
77 |
# 4. Workspace
|
78 |
+
def workspace_interface(project_name):
|
79 |
"""Manages projects, files, and resources in the workspace.
|
80 |
|
81 |
Args:
|
82 |
project_name: Name of the new project.
|
|
|
83 |
|
84 |
Returns:
|
85 |
+
Project creation status.
|
86 |
"""
|
87 |
# Create project directory
|
88 |
try:
|
|
|
90 |
status = f'Project \"{project_name}\" created successfully.'
|
91 |
except FileExistsError:
|
92 |
status = f'Project \"{project_name}\" already exists.'
|
93 |
+
return status
|
|
|
|
|
|
|
94 |
|
95 |
# 5. AI-Infused Tools
|
96 |
|
|
|
110 |
summary = summarizer(text, max_length=100, min_length=30)[0]['summary_text']
|
111 |
return summary
|
112 |
|
113 |
+
# Streamlit App
|
114 |
+
st.title("CodeCraft: Your AI-Powered Development Toolkit")
|
115 |
+
|
116 |
+
# Chat Interface
|
117 |
+
st.header("Chat with CodeCraft")
|
118 |
+
chat_input = st.text_area("Enter your message:")
|
119 |
+
if st.button("Send"):
|
120 |
+
chat_response = chat_interface(chat_input)
|
121 |
+
st.write(f"CodeCraft: {chat_response}")
|
122 |
+
|
123 |
+
# Terminal Interface
|
124 |
+
st.header("Terminal")
|
125 |
+
terminal_input = st.text_input("Enter a command:")
|
126 |
+
if st.button("Run"):
|
127 |
+
terminal_output = terminal_interface(terminal_input)
|
128 |
+
st.code(terminal_output, language="bash")
|
129 |
+
|
130 |
+
# Code Editor Interface
|
131 |
+
st.header("Code Editor")
|
132 |
+
code_editor = st.code_area("Write your code:", language="python")
|
133 |
+
if st.button("Format & Lint"):
|
134 |
+
formatted_code, lint_message = code_editor_interface(code_editor)
|
135 |
+
st.code(formatted_code, language="python")
|
136 |
+
st.info(lint_message)
|
137 |
+
|
138 |
+
# Workspace Interface
|
139 |
+
st.header("Workspace")
|
140 |
+
project_name = st.text_input("Enter project name:")
|
141 |
+
if st.button("Create Project"):
|
142 |
+
workspace_status = workspace_interface(project_name)
|
143 |
+
st.success(workspace_status)
|
144 |
+
|
145 |
+
# AI-Infused Tools
|
146 |
+
st.header("AI-Powered Tools")
|
147 |
+
text_to_summarize = st.text_area("Enter text to summarize:")
|
148 |
+
if st.button("Summarize"):
|
149 |
+
summary = summarize_text(text_to_summarize)
|
150 |
+
st.write(f"Summary: {summary}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|