""" Created By: ishwor subedi Date: 2024-10-03 """ import os import streamlit as st from datetime import datetime from groq import Groq from logic import LLMClient, CodeProcessor client = Groq(api_key=os.getenv("GROQ_API_KEY")) st.title("Code Analysis with LLMs") code_input_method = st.radio("How would you like to provide your code?", ("Paste Code", "Upload Code File")) code_text = "" if code_input_method == "Paste Code": code_text = st.text_area("Paste your code here:") elif code_input_method == "Upload Code File": uploaded_file = st.file_uploader("Upload your code file", type=["py", "txt"]) if uploaded_file is not None: code_text = uploaded_file.read().decode("utf-8") model_choice = st.selectbox("Select LLM Model", ["llama3-8b-8192", "gpt-4", "gpt-3.5-turbo"]) if st.button("Analyze Code") and code_text: llm_obj = LLMClient(client) processor = CodeProcessor(llm_obj) timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") markdown_output = processor.process_code(code_text, model_choice) st.markdown(markdown_output) st.download_button( label="Download Result as Markdown", data=markdown_output, file_name=f"code_analysis_{timestamp}.md", mime="text/markdown" ) else: st.write("Please paste or upload your code to analyze.")