Cristobal299 commited on
Commit
562244c
·
verified ·
1 Parent(s): 18306b1

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -1,20 +1,22 @@
1
  # -*- coding: utf-8 -*-
2
  import os
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,13 +24,13 @@ def improve_code(user_code, language):
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
 
1
  # -*- coding: utf-8 -*-
2
  import os
3
  import gradio as gr
4
+ import warnings
5
+ from starlette.exceptions import StarletteDeprecationWarning
6
+ warnings.filterwarnings("ignore", category=StarletteDeprecationWarning)
7
  import asyncio
8
  asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
9
+ import openai
10
 
11
+ # Load OpenAI API key from environment
12
+ openai_api_key = os.getenv("OPENAI_API_KEY")
13
+ if not openai_api_key:
14
+ openai_api_key = ""
15
+ openai.api_key = openai_api_key
 
16
 
17
  def improve_code(user_code, language):
18
  """
19
+ Sends the user code to OpenAI GPT model and asks for an improved version.
20
  """
21
  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."
22
  messages = [
 
24
  {"role": "user", "content": user_code}
25
  ]
26
  try:
27
+ response = openai.ChatCompletion.create(
28
+ model="gpt-3.5-turbo",
29
  messages=messages,
30
  temperature=0.2,
31
  max_tokens=1024,
32
+ n=1,
33
+ stop=None,
34
  )
35
  improved = response.choices[0].message.content.strip()
36
  return improved