puzan789 commited on
Commit
3632dc7
·
1 Parent(s): 179af5c

gemini added

Browse files
Files changed (4) hide show
  1. .env +0 -0
  2. app.py +16 -3
  3. logic.py +16 -8
  4. requirements.txt +2 -1
.env ADDED
File without changes
app.py CHANGED
@@ -6,10 +6,16 @@ from groq import Groq
6
  from logic import LLMClient, CodeProcessor
7
  from batch_code_logic_csv import csv_read_batch_code
8
  import zipfile
 
9
  import io
 
 
 
10
 
11
  client = Groq(api_key=os.getenv("GROQ_API_KEY"))
12
- llm_obj = LLMClient(client)
 
 
13
  processor = CodeProcessor(llm_obj)
14
 
15
  st.title("Code Analysis with LLMs")
@@ -32,10 +38,17 @@ elif code_input_method == "Upload Code File":
32
  uploaded_file = st.sidebar.file_uploader("Upload your code file", type=["py", "txt"])
33
  if uploaded_file is not None:
34
  code_text = uploaded_file.read().decode("utf-8")
35
- code_dict = {"single_code": code_text}
 
 
 
 
 
 
 
36
 
37
  model_choice = st.sidebar.selectbox("Select LLM Model",
38
- ["llama-3.2-90b-text-preview", "llama-3.2-90b-text-preview", "llama3-8b-8192"])
39
 
40
  if code_dict:
41
  unique_key = st.sidebar.selectbox("Select a Key for Analysis", list(code_dict.keys()))
 
6
  from logic import LLMClient, CodeProcessor
7
  from batch_code_logic_csv import csv_read_batch_code
8
  import zipfile
9
+ from dotenv import load_dotenv
10
  import io
11
+ import google.generativeai as genai
12
+ import re
13
+
14
 
15
  client = Groq(api_key=os.getenv("GROQ_API_KEY"))
16
+
17
+ GOOGLE_API_KEY=os.getenv('GOOGLE_API_KEY')
18
+ llm_obj = LLMClient(client,GOOGLE_API_KEY)
19
  processor = CodeProcessor(llm_obj)
20
 
21
  st.title("Code Analysis with LLMs")
 
38
  uploaded_file = st.sidebar.file_uploader("Upload your code file", type=["py", "txt"])
39
  if uploaded_file is not None:
40
  code_text = uploaded_file.read().decode("utf-8")
41
+
42
+ code_lines = [line.strip() for line in code_text.splitlines()]
43
+ code_lines = [re.sub(r"\s+", " ", line) for line in code_lines]
44
+
45
+ # Join the cleaned lines back if needed as a single string
46
+ clean_code_text = "\n".join(code_lines) # Combine lines into one string
47
+
48
+ code_dict = {"single_code": clean_code_text}
49
 
50
  model_choice = st.sidebar.selectbox("Select LLM Model",
51
+ ["llama-3.2-90b-text-preview", "llama-3.2-90b-text-preview", "llama3-8b-8192","llama-3.1-70b-versatile","gemma2-9b-it","gemini-pro"])
52
 
53
  if code_dict:
54
  unique_key = st.sidebar.selectbox("Select a Key for Analysis", list(code_dict.keys()))
logic.py CHANGED
@@ -1,15 +1,23 @@
 
1
  class LLMClient:
2
- def __init__(self, api_client):
3
  self.client = api_client
 
 
4
 
5
  def chat_completion(self, messages, model="llama3-8b-8192"):
6
- completion = self.client.chat.completions.create(
7
- messages=messages,
8
- model=model,
9
- temperature=0.5,
10
- stream=False,
11
- )
12
- return completion.choices[0].message.content
 
 
 
 
 
13
 
14
 
15
  class CodeProcessor:
 
1
+ import google.generativeai as genai
2
  class LLMClient:
3
+ def __init__(self, api_client,google_api_key):
4
  self.client = api_client
5
+ self.google_api_key = google_api_key # Google API key for Gemini
6
+ genai.configure(api_key=self.google_api_key)
7
 
8
  def chat_completion(self, messages, model="llama3-8b-8192"):
9
+ if model == "gemini-pro":
10
+ gemini_model = genai.GenerativeModel('gemini-pro')
11
+ response = gemini_model.generate_content([messages[1]['content']])
12
+ return response.text # Return the Gemini result
13
+ else:
14
+ completion = self.client.chat.completions.create(
15
+ messages=messages,
16
+ model=model,
17
+ temperature=0.5,
18
+ stream=False,
19
+ )
20
+ return completion.choices[0].message.content
21
 
22
 
23
  class CodeProcessor:
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  groq
2
  streamlit
3
  pandas
4
- numpy
 
 
1
  groq
2
  streamlit
3
  pandas
4
+ numpy
5
+ google-generativeai