Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
| 3 |
|
| 4 |
MODEL_ID = "Qwen/Qwen2.5-Coder-32B-Instruct"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
"You are an Elite Minecraft Modding and Environment Diagnostician.\n"
|
| 9 |
-
"The user is an experienced modder. Do NOT provide basic IT advice.\n\n"
|
| 10 |
-
"GOAL:\n"
|
| 11 |
-
"Analyze Minecraft crash reports (latest.log, crash-reports, hs_err_pid) and pinpoint the exact root cause.\n\n"
|
| 12 |
-
"CONSTRAINTS:\n"
|
| 13 |
-
"- Do NOT guess.\n"
|
| 14 |
-
"- Be concise and technical.\n\n"
|
| 15 |
-
"OUTPUT FORMAT:\n"
|
| 16 |
-
"1. Root Cause: One-line exact failure source.\n"
|
| 17 |
-
"2. Evidence: Exact log line or stack trace.\n"
|
| 18 |
-
"3. Fix: Direct actionable solution.\n"
|
| 19 |
-
)
|
| 20 |
|
| 21 |
-
# FIXED: Removed hf_token from arguments to match your Java payload (6 args total)
|
| 22 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 23 |
-
#
|
| 24 |
-
client = InferenceClient(model=MODEL_ID)
|
| 25 |
|
| 26 |
messages = [{"role": "system", "content": system_message}]
|
| 27 |
for user_msg, assistant_msg in history:
|
|
@@ -42,24 +30,24 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 42 |
response += token
|
| 43 |
yield response
|
| 44 |
except Exception as e:
|
|
|
|
| 45 |
yield f"API Error: {str(e)}"
|
| 46 |
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
gr.Markdown("# 🛠️ Minecraft Modding Log Analyzer")
|
| 49 |
|
| 50 |
with gr.Sidebar():
|
| 51 |
-
gr.LoginButton()
|
| 52 |
gr.Markdown("---")
|
| 53 |
-
system_msg = gr.Textbox(value=
|
| 54 |
-
tokens = gr.Slider(128, 8192, value=2048, label="Max
|
| 55 |
-
temp = gr.Slider(0.1, 1.0, value=0.3, label="
|
| 56 |
top_p = gr.Slider(0.1, 1.0, value=0.9, label="Top-P")
|
| 57 |
|
| 58 |
-
# FIXED: ChatInterface now passes exactly 6 arguments to respond()
|
| 59 |
gr.ChatInterface(
|
| 60 |
respond,
|
| 61 |
additional_inputs=[system_msg, tokens, temp, top_p],
|
| 62 |
)
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
-
demo.launch(
|
|
|
|
| 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:
|
|
|
|
| 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")
|
| 46 |
|
|
|
|
| 47 |
gr.ChatInterface(
|
| 48 |
respond,
|
| 49 |
additional_inputs=[system_msg, tokens, temp, top_p],
|
| 50 |
)
|
| 51 |
|
| 52 |
if __name__ == "__main__":
|
| 53 |
+
demo.launch()
|