Spaces:
Sleeping
Sleeping
File size: 3,192 Bytes
c0e81fb 1367fa8 c0e81fb 145f26c c0e81fb 4e33c9b 1367fa8 c0e81fb 4e33c9b c0e81fb 1367fa8 c0e81fb 1367fa8 c0e81fb 1367fa8 c0e81fb 1367fa8 c0e81fb 1367fa8 c0e81fb 1367fa8 c0e81fb 1367fa8 |
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 |
import os
import streamlit as st
from datetime import datetime
from groq import Groq
from logic import LLMClient, CodeProcessor
from batch_code_logic_csv import csv_read_batch_code
import zipfile
import io
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
st.title("Code Analysis with LLMs")
st.sidebar.title("Input Options")
code_input_method = st.sidebar.radio("How would you like to provide your code?",
("Upload CSV file", "Upload Code File"))
code_dict = {}
if code_input_method == "Upload CSV file":
uploaded_file = st.sidebar.file_uploader("Upload your CSV/Excel file", type=["csv", "xlsx"])
if uploaded_file is not None:
code_dict = csv_read_batch_code(uploaded_file) # returns a dict with keys and code snippets
elif code_input_method == "Upload Code File":
uploaded_file = st.sidebar.file_uploader("Upload your code file", type=["py", "txt"])
if uploaded_file is not None:
code_text = uploaded_file.read().decode("utf-8")
code_dict = {"single_code": code_text} # Wrap in dict for consistency
model_choice = st.sidebar.selectbox("Select LLM Model",
["llama-3.2-90b-text-preview", "llama-3.2-90b-text-preview", "llama3-8b-8192"])
if code_dict:
unique_key = st.sidebar.selectbox("Select a Key for Analysis", list(code_dict.keys()))
if st.sidebar.button("Analyze Code") and unique_key:
llm_obj = LLMClient(client)
processor = CodeProcessor(llm_obj)
code_text = code_dict[unique_key]
markdown_output = processor.process_code(code_text, model_choice)
with st.expander(f"Analysis for {unique_key}"):
st.markdown(markdown_output)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
st.download_button(
label=f"Download {unique_key} Result as Markdown",
data=markdown_output,
file_name=f"code_analysis_{unique_key}_{timestamp}.md",
mime="text/markdown"
)
if st.sidebar.button("Batch Predict"):
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
all_markdowns = {}
for key, code_text in code_dict.items():
markdown_output = processor.process_code(code_text, model_choice)
all_markdowns[key] = markdown_output
with st.expander(f"Analysis for {key}"):
st.markdown(markdown_output)
st.download_button(
label=f"Download {key} Result as Markdown",
data=markdown_output,
file_name=f"code_analysis_{key}_{timestamp}.md",
mime="text/markdown"
)
zip_buffer = io.BytesIO()
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
for key, markdown_output in all_markdowns.items():
zip_file.writestr(f"code_analysis_{key}_{timestamp}.md", markdown_output)
st.download_button(
label="Download All as Zip",
data=zip_buffer.getvalue(),
file_name=f"code_analysis_batch_{timestamp}.zip",
mime="application/zip"
)
else:
st.write("Please upload your file to analyze.")
|