Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
MODEL_ID = "
|
| 6 |
|
| 7 |
-
# Retrieve the
|
| 8 |
-
|
| 9 |
|
| 10 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 11 |
-
#
|
| 12 |
-
client =
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
messages = [{"role": "system", "content": system_message}]
|
| 15 |
for user_msg, assistant_msg in history:
|
|
@@ -19,27 +22,31 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 19 |
|
| 20 |
response = ""
|
| 21 |
try:
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
temperature=temperature,
|
| 27 |
-
top_p=top_p
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
except Exception as e:
|
| 33 |
-
# This will show you exactly what is wrong if it still fails
|
| 34 |
yield f"API Error: {str(e)}"
|
| 35 |
|
| 36 |
with gr.Blocks() as demo:
|
| 37 |
gr.Markdown("# 🛠️ Minecraft Modding Log Analyzer")
|
| 38 |
|
| 39 |
with gr.Sidebar():
|
| 40 |
-
gr.LoginButton()
|
| 41 |
gr.Markdown("---")
|
| 42 |
-
system_msg = gr.Textbox(value="You are an Elite Minecraft Modder.
|
| 43 |
tokens = gr.Slider(128, 8192, value=2048, label="Max Tokens")
|
| 44 |
temp = gr.Slider(0.1, 1.0, value=0.3, label="Temp")
|
| 45 |
top_p = gr.Slider(0.1, 1.0, value=0.9, label="Top-P")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from openai import OpenAI
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
MODEL_ID = "llama-3.3-70b"
|
| 6 |
|
| 7 |
+
# Retrieve the Cerebras key from Space Secrets
|
| 8 |
+
CEREBRAS_API_KEY = os.getenv("CEREBRAS_API_KEY")
|
| 9 |
|
| 10 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 11 |
+
# Initialize the Cerebras client (OpenAI-compatible)
|
| 12 |
+
client = OpenAI(
|
| 13 |
+
base_url="https://api.cerebras.ai/v1",
|
| 14 |
+
api_key=CEREBRAS_API_KEY
|
| 15 |
+
)
|
| 16 |
|
| 17 |
messages = [{"role": "system", "content": system_message}]
|
| 18 |
for user_msg, assistant_msg in history:
|
|
|
|
| 22 |
|
| 23 |
response = ""
|
| 24 |
try:
|
| 25 |
+
stream = client.chat.completions.create(
|
| 26 |
+
model=MODEL_ID,
|
| 27 |
+
messages=messages,
|
| 28 |
+
max_tokens=max_tokens,
|
| 29 |
+
temperature=temperature,
|
| 30 |
+
top_p=top_p,
|
| 31 |
+
stream=True
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
for chunk in stream:
|
| 35 |
+
if chunk.choices[0].delta.content:
|
| 36 |
+
token = chunk.choices[0].delta.content
|
| 37 |
+
response += token
|
| 38 |
+
yield response
|
| 39 |
+
|
| 40 |
except Exception as e:
|
|
|
|
| 41 |
yield f"API Error: {str(e)}"
|
| 42 |
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
gr.Markdown("# 🛠️ Minecraft Modding Log Analyzer")
|
| 45 |
|
| 46 |
with gr.Sidebar():
|
| 47 |
+
gr.LoginButton()
|
| 48 |
gr.Markdown("---")
|
| 49 |
+
system_msg = gr.Textbox(value="You are an Elite Minecraft Modder who fixes Fabric and Forge crash logs.", label="System Prompt")
|
| 50 |
tokens = gr.Slider(128, 8192, value=2048, label="Max Tokens")
|
| 51 |
temp = gr.Slider(0.1, 1.0, value=0.3, label="Temp")
|
| 52 |
top_p = gr.Slider(0.1, 1.0, value=0.9, label="Top-P")
|