Cristobal299 commited on
Commit
4b98be0
·
verified ·
1 Parent(s): 2014456

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -3,17 +3,18 @@ import os
3
  import gradio as gr
4
  import asyncio
5
  asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
6
- import openai
7
 
8
- # Load OpenAI API key from environment
9
- openai_api_key = os.getenv("OPENAI_API_KEY")
10
- if not openai_api_key:
11
- openai_api_key = ""
12
- openai.api_key = openai_api_key
 
13
 
14
  def improve_code(user_code, language):
15
  """
16
- Sends the user code to OpenAI GPT model and asks for an improved version.
17
  """
18
  system_prompt = f"You are an expert {language} developer. Refactor and improve the following code. Keep the same functionality but make it cleaner, more efficient and well commented."
19
  messages = [
@@ -21,13 +22,13 @@ def improve_code(user_code, language):
21
  {"role": "user", "content": user_code}
22
  ]
23
  try:
24
- response = openai.ChatCompletion.create(
25
- model="gpt-3.5-turbo",
26
  messages=messages,
27
  temperature=0.2,
28
  max_tokens=1024,
29
- n=1,
30
- stop=None,
31
  )
32
  improved = response.choices[0].message.content.strip()
33
  return improved
 
3
  import gradio as gr
4
  import asyncio
5
  asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
6
+ from groq import Groq
7
 
8
+ # Load Groq API key from environment
9
+ groq_api_key = os.getenv("GROQ_API_KEY")
10
+ if not groq_api_key:
11
+ groq_api_key = ""
12
+
13
+ client = Groq(api_key=groq_api_key)
14
 
15
  def improve_code(user_code, language):
16
  """
17
+ Sends the user code to Groq LLM and asks for an improved version.
18
  """
19
  system_prompt = f"You are an expert {language} developer. Refactor and improve the following code. Keep the same functionality but make it cleaner, more efficient and well commented."
20
  messages = [
 
22
  {"role": "user", "content": user_code}
23
  ]
24
  try:
25
+ response = client.chat.completions.create(
26
+ model="llama3-8b-8192",
27
  messages=messages,
28
  temperature=0.2,
29
  max_tokens=1024,
30
+ top_p=1,
31
+ stream=False,
32
  )
33
  improved = response.choices[0].message.content.strip()
34
  return improved