File size: 1,329 Bytes
c0e81fb
 
 
 
 
 
 
 
 
 
145f26c
c0e81fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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.")