Update app.py
Browse files
app.py
CHANGED
|
@@ -20,6 +20,14 @@ import matplotlib.pyplot as plt
|
|
| 20 |
import seaborn as sns
|
| 21 |
from IPython.display import display
|
| 22 |
from tenacity import retry, stop_after_attempt, wait_fixed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Configure the Gemini API
|
| 25 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
|
@@ -49,6 +57,7 @@ def generate_response(user_input):
|
|
| 49 |
response = chat_session.send_message(user_input)
|
| 50 |
return response.text
|
| 51 |
except Exception as e:
|
|
|
|
| 52 |
return f"Error: {e}"
|
| 53 |
|
| 54 |
def optimize_code(code):
|
|
@@ -81,6 +90,7 @@ def train_ml_model(code_data):
|
|
| 81 |
|
| 82 |
def handle_error(error):
|
| 83 |
"""Handle errors and log them."""
|
|
|
|
| 84 |
st.error(f"An error occurred: {error}")
|
| 85 |
|
| 86 |
def initialize_git_repo(repo_path):
|
|
@@ -142,6 +152,7 @@ def execute_code_in_docker(code):
|
|
| 142 |
logs = container.logs().decode('utf-8')
|
| 143 |
return logs, result['StatusCode']
|
| 144 |
except Exception as e:
|
|
|
|
| 145 |
return f"Error: {e}", 1
|
| 146 |
|
| 147 |
def solve_equation(equation):
|
|
@@ -175,6 +186,38 @@ def display_dataframe(data):
|
|
| 175 |
df = pd.DataFrame(data)
|
| 176 |
display(df)
|
| 177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
# Streamlit UI setup
|
| 179 |
st.set_page_config(page_title="Ultra AI Code Assistant", page_icon="π", layout="wide")
|
| 180 |
|
|
|
|
| 20 |
import seaborn as sns
|
| 21 |
from IPython.display import display
|
| 22 |
from tenacity import retry, stop_after_attempt, wait_fixed
|
| 23 |
+
from transformers import pipeline
|
| 24 |
+
import tensorflow as tf
|
| 25 |
+
import torch
|
| 26 |
+
import json
|
| 27 |
+
import logging
|
| 28 |
+
|
| 29 |
+
# Configure logging
|
| 30 |
+
logging.basicConfig(level=logging.INFO)
|
| 31 |
|
| 32 |
# Configure the Gemini API
|
| 33 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
|
|
|
| 57 |
response = chat_session.send_message(user_input)
|
| 58 |
return response.text
|
| 59 |
except Exception as e:
|
| 60 |
+
logging.error(f"Error generating response: {e}")
|
| 61 |
return f"Error: {e}"
|
| 62 |
|
| 63 |
def optimize_code(code):
|
|
|
|
| 90 |
|
| 91 |
def handle_error(error):
|
| 92 |
"""Handle errors and log them."""
|
| 93 |
+
logging.error(f"An error occurred: {error}")
|
| 94 |
st.error(f"An error occurred: {error}")
|
| 95 |
|
| 96 |
def initialize_git_repo(repo_path):
|
|
|
|
| 152 |
logs = container.logs().decode('utf-8')
|
| 153 |
return logs, result['StatusCode']
|
| 154 |
except Exception as e:
|
| 155 |
+
logging.error(f"Error executing code in Docker: {e}")
|
| 156 |
return f"Error: {e}", 1
|
| 157 |
|
| 158 |
def solve_equation(equation):
|
|
|
|
| 186 |
df = pd.DataFrame(data)
|
| 187 |
display(df)
|
| 188 |
|
| 189 |
+
def generate_text(prompt):
|
| 190 |
+
"""Generate text using a pre-trained transformer model."""
|
| 191 |
+
generator = pipeline('text-generation', model='gpt2')
|
| 192 |
+
result = generator(prompt, max_length=50, num_return_sequences=1)
|
| 193 |
+
return result[0]['generated_text']
|
| 194 |
+
|
| 195 |
+
def classify_text(text):
|
| 196 |
+
"""Classify text using a pre-trained transformer model."""
|
| 197 |
+
classifier = pipeline('sentiment-analysis')
|
| 198 |
+
result = classifier(text)
|
| 199 |
+
return result
|
| 200 |
+
|
| 201 |
+
def predict_with_tensorflow(model_path, data):
|
| 202 |
+
"""Make predictions using a TensorFlow model."""
|
| 203 |
+
model = tf.keras.models.load_model(model_path)
|
| 204 |
+
predictions = model.predict(data)
|
| 205 |
+
return predictions
|
| 206 |
+
|
| 207 |
+
def predict_with_pytorch(model_path, data):
|
| 208 |
+
"""Make predictions using a PyTorch model."""
|
| 209 |
+
model = torch.load(model_path)
|
| 210 |
+
model.eval()
|
| 211 |
+
with torch.no_grad():
|
| 212 |
+
predictions = model(data)
|
| 213 |
+
return predictions
|
| 214 |
+
|
| 215 |
+
def load_json_config(config_path):
|
| 216 |
+
"""Load a JSON configuration file."""
|
| 217 |
+
with open(config_path, 'r') as file:
|
| 218 |
+
config = json.load(file)
|
| 219 |
+
return config
|
| 220 |
+
|
| 221 |
# Streamlit UI setup
|
| 222 |
st.set_page_config(page_title="Ultra AI Code Assistant", page_icon="π", layout="wide")
|
| 223 |
|