eleeter commited on
Commit
fabc210
·
verified ·
1 Parent(s): 716bb52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -19
app.py CHANGED
@@ -1,15 +1,18 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
  import os
4
 
5
- MODEL_ID = "Qwen/Qwen2.5-Coder-32B-Instruct"
6
 
7
- # Retrieve the token you just added to the Space Settings
8
- HF_TOKEN = os.getenv("HF_TOKEN")
9
 
10
  def respond(message, history, system_message, max_tokens, temperature, top_p):
11
- # Pass the token here so the API allows the request
12
- client = InferenceClient(model=MODEL_ID, token=HF_TOKEN)
 
 
 
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
- for message_chunk in client.chat_completion(
23
- messages,
24
- max_tokens=max_tokens,
25
- stream=True,
26
- temperature=temperature,
27
- top_p=top_p
28
- ):
29
- token = message_chunk.choices[0].delta.content or ""
30
- response += token
31
- yield response
 
 
 
 
 
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() # Still keep this for web users
41
  gr.Markdown("---")
42
- system_msg = gr.Textbox(value="You are an Elite Minecraft Modder...", label="System Prompt")
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")