Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import logging
|
|
5 |
|
6 |
os.environ["GROQ_API_KEY"] = "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"
|
7 |
|
8 |
-
|
9 |
logging.basicConfig(level=logging.DEBUG)
|
10 |
logger = logging.getLogger(__name__)
|
11 |
|
@@ -20,6 +19,9 @@ MODEL_NAME = os.environ.get("MODEL_NAME", "llama3-8b-8192")
|
|
20 |
|
21 |
# Define a function to handle chat completions
|
22 |
def get_completion(user_input):
|
|
|
|
|
|
|
23 |
try:
|
24 |
completion = client.chat.completions.create(
|
25 |
model=MODEL_NAME,
|
@@ -38,7 +40,7 @@ def get_completion(user_input):
|
|
38 |
for chunk in completion:
|
39 |
response += chunk.choices[0].delta.content or ""
|
40 |
|
41 |
-
return response
|
42 |
except Exception as e:
|
43 |
logger.error(f"Error during completion: {e}")
|
44 |
return "Sorry, I encountered an error while processing your request."
|
@@ -65,8 +67,13 @@ def launch_interface():
|
|
65 |
title="Mr AI",
|
66 |
description="Ask anything and get a helpful response.",
|
67 |
theme="default",
|
68 |
-
css="
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
70 |
)
|
71 |
|
72 |
logger.info("Starting Gradio interface")
|
|
|
5 |
|
6 |
os.environ["GROQ_API_KEY"] = "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"
|
7 |
|
|
|
8 |
logging.basicConfig(level=logging.DEBUG)
|
9 |
logger = logging.getLogger(__name__)
|
10 |
|
|
|
19 |
|
20 |
# Define a function to handle chat completions
|
21 |
def get_completion(user_input):
|
22 |
+
if not user_input.strip():
|
23 |
+
return "Please enter a valid query."
|
24 |
+
|
25 |
try:
|
26 |
completion = client.chat.completions.create(
|
27 |
model=MODEL_NAME,
|
|
|
40 |
for chunk in completion:
|
41 |
response += chunk.choices[0].delta.content or ""
|
42 |
|
43 |
+
return response.strip() # Clean up response
|
44 |
except Exception as e:
|
45 |
logger.error(f"Error during completion: {e}")
|
46 |
return "Sorry, I encountered an error while processing your request."
|
|
|
67 |
title="Mr AI",
|
68 |
description="Ask anything and get a helpful response.",
|
69 |
theme="default",
|
70 |
+
css="""
|
71 |
+
.gr-box { border-radius: 10px; border: 1px solid #ccc; padding: 10px; }
|
72 |
+
.gr-button { background-color: #4CAF50; color: white; }
|
73 |
+
.gr-textbox { border-radius: 5px; }
|
74 |
+
""",
|
75 |
+
allow_flagging="never",
|
76 |
+
live=True, # Enable live updates if supported
|
77 |
)
|
78 |
|
79 |
logger.info("Starting Gradio interface")
|