Update app.py
Browse files
app.py
CHANGED
|
@@ -8,72 +8,68 @@ DEFAULT_SYSTEM_PROMPT = (
|
|
| 8 |
"ROLE:\n"
|
| 9 |
"You are an Elite Minecraft Modding and Environment Diagnostician.\n"
|
| 10 |
"The user is an experienced modder. Do NOT provide basic IT advice.\n\n"
|
| 11 |
-
|
| 12 |
"GOAL:\n"
|
| 13 |
"Analyze Minecraft crash reports (latest.log, crash-reports, hs_err_pid) and pinpoint the exact root cause.\n"
|
| 14 |
"Identify whether the issue is caused by a specific mod, mod conflict, library, JVM configuration, or hardware/driver issue.\n\n"
|
| 15 |
-
|
| 16 |
"KNOWLEDGE DOMAINS:\n"
|
| 17 |
"1. Java/JVM & Environment:\n"
|
| 18 |
"- Detect incorrect Java versions (Java 8 vs 17 vs 21 mismatches).\n"
|
| 19 |
"- Identify GC overhead errors, invalid JVM flags, and memory leaks.\n"
|
| 20 |
"- Diagnose hs_err_pid crashes (native crashes, lwjgl corruption).\n\n"
|
| 21 |
-
|
| 22 |
"2. Hardware & OS:\n"
|
| 23 |
"- Diagnose EXCEPTION_ACCESS_VIOLATION (0xc0000005).\n"
|
| 24 |
"- Detect GL_OUT_OF_MEMORY and OpenGL issues.\n"
|
| 25 |
"- Identify wrong GPU usage (integrated vs dedicated).\n"
|
| 26 |
"- Detect outdated or incompatible graphics drivers.\n\n"
|
| 27 |
-
|
| 28 |
"3. Modloader & Mixins:\n"
|
| 29 |
"- Trace NoSuchMethodError, ClassNotFoundException, AbstractMethodError to exact modid.\n"
|
| 30 |
"- Analyze Mixin conflicts, failed injections, OVERWRITE/REDIRECT failures.\n"
|
| 31 |
"- Detect duplicate or incompatible mods.\n\n"
|
| 32 |
-
|
| 33 |
"4. Rendering Conflicts:\n"
|
| 34 |
"- Detect conflicts between OptiFine, Sodium/Rubidium/Embeddium, Iris/Oculus.\n\n"
|
| 35 |
-
|
| 36 |
"5. Data/Config Issues:\n"
|
| 37 |
"- Detect malformed JSON configs.\n"
|
| 38 |
"- Identify corrupted world data (level.dat).\n"
|
| 39 |
"- Detect missing dependencies or broken datapacks.\n\n"
|
| 40 |
-
|
| 41 |
"CONSTRAINTS:\n"
|
| 42 |
"- Do NOT guess.\n"
|
| 43 |
"- Do NOT hallucinate mod names or file paths.\n"
|
| 44 |
"- If stack trace shows net.minecraft.*, scan deeper to find injected mod.\n"
|
| 45 |
"- In Mixin conflicts, identify the actual instigator.\n"
|
| 46 |
"- Be concise and technical.\n\n"
|
| 47 |
-
|
| 48 |
"OUTPUT FORMAT:\n"
|
| 49 |
"1. Root Cause: One-line exact failure source.\n"
|
| 50 |
"2. Evidence: Exact log line, stack trace, or error code.\n"
|
| 51 |
"3. Fix: Direct actionable solution.\n"
|
| 52 |
)
|
| 53 |
|
| 54 |
-
def respond(message, history, system_message, max_tokens, temperature, top_p
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
messages = [{"role": "system", "content": system_message}]
|
| 58 |
-
for
|
| 59 |
-
if
|
| 60 |
-
if
|
| 61 |
messages.append({"role": "user", "content": message})
|
| 62 |
|
| 63 |
response = ""
|
| 64 |
try:
|
| 65 |
-
# Qwen models are very fast on the HF API
|
| 66 |
for message_chunk in client.chat_completion(
|
| 67 |
-
messages,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
):
|
| 69 |
token = message_chunk.choices[0].delta.content or ""
|
| 70 |
response += token
|
| 71 |
yield response
|
| 72 |
except Exception as e:
|
| 73 |
-
yield f"API Error: {str(e)}.
|
| 74 |
|
| 75 |
# Gradio Interface
|
| 76 |
-
with gr.Blocks(
|
| 77 |
gr.Markdown("# 🛠️ Minecraft Modding Log Analyzer")
|
| 78 |
|
| 79 |
with gr.Sidebar():
|
|
@@ -81,13 +77,16 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
| 81 |
gr.Markdown("---")
|
| 82 |
system_msg = gr.Textbox(value=DEFAULT_SYSTEM_PROMPT, label="Modder Persona", lines=5)
|
| 83 |
tokens = gr.Slider(128, 8192, value=2048, label="Max Log Length")
|
| 84 |
-
temp = gr.Slider(0.1, 1.0, value=0.3, label="Creativity
|
| 85 |
top_p = gr.Slider(0.1, 1.0, value=0.9, label="Top-P")
|
| 86 |
|
|
|
|
|
|
|
| 87 |
gr.ChatInterface(
|
| 88 |
respond,
|
| 89 |
additional_inputs=[system_msg, tokens, temp, top_p],
|
| 90 |
)
|
| 91 |
|
| 92 |
if __name__ == "__main__":
|
| 93 |
-
|
|
|
|
|
|
| 8 |
"ROLE:\n"
|
| 9 |
"You are an Elite Minecraft Modding and Environment Diagnostician.\n"
|
| 10 |
"The user is an experienced modder. Do NOT provide basic IT advice.\n\n"
|
|
|
|
| 11 |
"GOAL:\n"
|
| 12 |
"Analyze Minecraft crash reports (latest.log, crash-reports, hs_err_pid) and pinpoint the exact root cause.\n"
|
| 13 |
"Identify whether the issue is caused by a specific mod, mod conflict, library, JVM configuration, or hardware/driver issue.\n\n"
|
|
|
|
| 14 |
"KNOWLEDGE DOMAINS:\n"
|
| 15 |
"1. Java/JVM & Environment:\n"
|
| 16 |
"- Detect incorrect Java versions (Java 8 vs 17 vs 21 mismatches).\n"
|
| 17 |
"- Identify GC overhead errors, invalid JVM flags, and memory leaks.\n"
|
| 18 |
"- Diagnose hs_err_pid crashes (native crashes, lwjgl corruption).\n\n"
|
|
|
|
| 19 |
"2. Hardware & OS:\n"
|
| 20 |
"- Diagnose EXCEPTION_ACCESS_VIOLATION (0xc0000005).\n"
|
| 21 |
"- Detect GL_OUT_OF_MEMORY and OpenGL issues.\n"
|
| 22 |
"- Identify wrong GPU usage (integrated vs dedicated).\n"
|
| 23 |
"- Detect outdated or incompatible graphics drivers.\n\n"
|
|
|
|
| 24 |
"3. Modloader & Mixins:\n"
|
| 25 |
"- Trace NoSuchMethodError, ClassNotFoundException, AbstractMethodError to exact modid.\n"
|
| 26 |
"- Analyze Mixin conflicts, failed injections, OVERWRITE/REDIRECT failures.\n"
|
| 27 |
"- Detect duplicate or incompatible mods.\n\n"
|
|
|
|
| 28 |
"4. Rendering Conflicts:\n"
|
| 29 |
"- Detect conflicts between OptiFine, Sodium/Rubidium/Embeddium, Iris/Oculus.\n\n"
|
|
|
|
| 30 |
"5. Data/Config Issues:\n"
|
| 31 |
"- Detect malformed JSON configs.\n"
|
| 32 |
"- Identify corrupted world data (level.dat).\n"
|
| 33 |
"- Detect missing dependencies or broken datapacks.\n\n"
|
|
|
|
| 34 |
"CONSTRAINTS:\n"
|
| 35 |
"- Do NOT guess.\n"
|
| 36 |
"- Do NOT hallucinate mod names or file paths.\n"
|
| 37 |
"- If stack trace shows net.minecraft.*, scan deeper to find injected mod.\n"
|
| 38 |
"- In Mixin conflicts, identify the actual instigator.\n"
|
| 39 |
"- Be concise and technical.\n\n"
|
|
|
|
| 40 |
"OUTPUT FORMAT:\n"
|
| 41 |
"1. Root Cause: One-line exact failure source.\n"
|
| 42 |
"2. Evidence: Exact log line, stack trace, or error code.\n"
|
| 43 |
"3. Fix: Direct actionable solution.\n"
|
| 44 |
)
|
| 45 |
|
| 46 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 47 |
+
# This retrieves the token from the session automatically if logged in via gr.LoginButton
|
| 48 |
+
client = InferenceClient(model=MODEL_ID)
|
| 49 |
|
| 50 |
messages = [{"role": "system", "content": system_message}]
|
| 51 |
+
for user_msg, assistant_msg in history:
|
| 52 |
+
if user_msg: messages.append({"role": "user", "content": user_msg})
|
| 53 |
+
if assistant_msg: messages.append({"role": "assistant", "content": assistant_msg})
|
| 54 |
messages.append({"role": "user", "content": message})
|
| 55 |
|
| 56 |
response = ""
|
| 57 |
try:
|
|
|
|
| 58 |
for message_chunk in client.chat_completion(
|
| 59 |
+
messages,
|
| 60 |
+
max_tokens=max_tokens,
|
| 61 |
+
stream=True,
|
| 62 |
+
temperature=temperature,
|
| 63 |
+
top_p=top_p
|
| 64 |
):
|
| 65 |
token = message_chunk.choices[0].delta.content or ""
|
| 66 |
response += token
|
| 67 |
yield response
|
| 68 |
except Exception as e:
|
| 69 |
+
yield f"API Error: {str(e)}. Make sure you are logged in via the Sidebar."
|
| 70 |
|
| 71 |
# Gradio Interface
|
| 72 |
+
with gr.Blocks() as demo:
|
| 73 |
gr.Markdown("# 🛠️ Minecraft Modding Log Analyzer")
|
| 74 |
|
| 75 |
with gr.Sidebar():
|
|
|
|
| 77 |
gr.Markdown("---")
|
| 78 |
system_msg = gr.Textbox(value=DEFAULT_SYSTEM_PROMPT, label="Modder Persona", lines=5)
|
| 79 |
tokens = gr.Slider(128, 8192, value=2048, label="Max Log Length")
|
| 80 |
+
temp = gr.Slider(0.1, 1.0, value=0.3, label="Creativity")
|
| 81 |
top_p = gr.Slider(0.1, 1.0, value=0.9, label="Top-P")
|
| 82 |
|
| 83 |
+
# The additional_inputs must exactly match the arguments in respond()
|
| 84 |
+
# after 'message' and 'history'
|
| 85 |
gr.ChatInterface(
|
| 86 |
respond,
|
| 87 |
additional_inputs=[system_msg, tokens, temp, top_p],
|
| 88 |
)
|
| 89 |
|
| 90 |
if __name__ == "__main__":
|
| 91 |
+
# Theme is applied here for Gradio 6.0 compatibility
|
| 92 |
+
demo.launch(theme=gr.themes.Monochrome())
|