Spaces:
Runtime error
Runtime error
File size: 3,511 Bytes
5dd070e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
import streamlit as st
import os
import time
from datetime import datetime
import pandas as pd
# Handle missing plotly dependency
try:
import plotly.express as px
except ImportError:
px = None
def set_page_config():
"""Set the page configuration with title and layout."""
st.set_page_config(
page_title="CodeGen Hub",
page_icon="💻",
layout="wide",
initial_sidebar_state="expanded"
)
def display_sidebar():
"""Display sidebar with navigation options."""
st.sidebar.title("CodeGen Hub")
st.sidebar.markdown("---")
st.sidebar.subheader("Navigation")
st.sidebar.markdown("""
- [Home](/)
- [Dataset Management](/Dataset_Management)
- [Model Training](/Model_Training)
- [Code Generation](/Code_Generation)
""")
st.sidebar.markdown("---")
st.sidebar.subheader("Resources")
st.sidebar.markdown("""
- [Hugging Face Hub](https://huggingface.co/models)
- [Transformers Documentation](https://huggingface.co/docs/transformers/index)
- [Streamlit Documentation](https://docs.streamlit.io/)
""")
st.sidebar.markdown("---")
st.sidebar.caption("© 2023 CodeGen Hub")
def timestamp():
"""Return a formatted timestamp for logging."""
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def add_log(message, log_type="INFO"):
"""Add a log message to the training logs."""
log_entry = f"[{timestamp()}] [{log_type}] {message}"
if 'training_logs' not in st.session_state:
st.session_state.training_logs = []
st.session_state.training_logs.append(log_entry)
return log_entry
def display_logs():
"""Display the training logs in a text area."""
if 'training_logs' in st.session_state and st.session_state.training_logs:
logs = '\n'.join(st.session_state.training_logs)
st.text_area('Training Logs', logs, height=300)
else:
st.text_area('Training Logs', 'No logs available.', height=300)
def plot_training_progress(model_id):
"""Plot training progress for a model."""
if 'training_progress' in st.session_state and model_id in st.session_state.training_progress:
progress = st.session_state.training_progress[model_id]
if 'loss_history' in progress and progress['loss_history']:
# Create DataFrame for plotting
df = pd.DataFrame({
'Step': list(range(1, len(progress['loss_history']) + 1)),
'Loss': progress['loss_history']
})
if px is not None:
# Create plot with plotly if available
fig = px.line(df, x='Step', y='Loss', title=f'Training Loss for {model_id}')
fig.update_layout(height=400)
st.plotly_chart(fig, use_container_width=True)
else:
# Fallback to simple display without plotly
st.subheader(f"Training Loss for {model_id}")
st.dataframe(df)
st.info("Install plotly for interactive charts")
else:
st.info("No training progress data available yet.")
else:
st.info("No training progress data available for this model.")
def format_code(code):
"""Format code for display."""
return code.strip()
def create_folder_if_not_exists(folder_path):
"""Create folder if it doesn't exist."""
if not os.path.exists(folder_path):
os.makedirs(folder_path)
return True
return False
|