Spaces:
Paused
Paused
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -6,17 +6,17 @@ from starlette.exceptions import StarletteDeprecationWarning
|
|
| 6 |
warnings.filterwarnings("ignore", category=StarletteDeprecationWarning)
|
| 7 |
import asyncio
|
| 8 |
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
|
| 9 |
-
import
|
| 10 |
|
| 11 |
-
# Load
|
| 12 |
-
|
| 13 |
-
if not
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
def improve_code(user_code, language):
|
| 18 |
"""
|
| 19 |
-
Sends the user code to
|
| 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,8 +24,8 @@ def improve_code(user_code, language):
|
|
| 24 |
{"role": "user", "content": user_code}
|
| 25 |
]
|
| 26 |
try:
|
| 27 |
-
response =
|
| 28 |
-
model="
|
| 29 |
messages=messages,
|
| 30 |
temperature=0.2,
|
| 31 |
max_tokens=1024,
|
|
|
|
| 6 |
warnings.filterwarnings("ignore", category=StarletteDeprecationWarning)
|
| 7 |
import asyncio
|
| 8 |
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
|
| 9 |
+
import groq
|
| 10 |
|
| 11 |
+
# Load Groq API key from environment
|
| 12 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 13 |
+
if not groq_api_key:
|
| 14 |
+
groq_api_key = ""
|
| 15 |
+
groq.api_key = groq_api_key
|
| 16 |
|
| 17 |
def improve_code(user_code, language):
|
| 18 |
"""
|
| 19 |
+
Sends the user code to Groq 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 = groq.ChatCompletion.create(
|
| 28 |
+
model="mixtral-8x7b-32768",
|
| 29 |
messages=messages,
|
| 30 |
temperature=0.2,
|
| 31 |
max_tokens=1024,
|