Update app.py
Browse files
app.py
CHANGED
|
@@ -1,96 +1,93 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
DEFAULT_SYSTEM_PROMPT = (
|
| 7 |
-
"
|
| 8 |
-
"
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
)
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
""
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
model=MODEL_ID
|
| 27 |
-
)
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
messages = [{"role": "system", "content": system_message}]
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
messages.append({"role": "user", "content": message})
|
| 33 |
|
| 34 |
response = ""
|
| 35 |
-
|
| 36 |
-
# Stream the response from DeepSeek
|
| 37 |
try:
|
|
|
|
| 38 |
for message_chunk in client.chat_completion(
|
| 39 |
-
messages,
|
| 40 |
-
max_tokens=max_tokens,
|
| 41 |
-
stream=True,
|
| 42 |
-
temperature=temperature,
|
| 43 |
-
top_p=top_p,
|
| 44 |
):
|
| 45 |
token = message_chunk.choices[0].delta.content or ""
|
| 46 |
response += token
|
| 47 |
yield response
|
| 48 |
except Exception as e:
|
| 49 |
-
yield f"
|
| 50 |
-
|
| 51 |
-
# Define the Gradio ChatInterface
|
| 52 |
-
chatbot = gr.ChatInterface(
|
| 53 |
-
respond,
|
| 54 |
-
additional_inputs=[
|
| 55 |
-
gr.Textbox(
|
| 56 |
-
value=DEFAULT_SYSTEM_PROMPT,
|
| 57 |
-
label="System message"
|
| 58 |
-
),
|
| 59 |
-
gr.Slider(
|
| 60 |
-
minimum=1,
|
| 61 |
-
maximum=8192,
|
| 62 |
-
value=4096,
|
| 63 |
-
step=1,
|
| 64 |
-
label="Max new tokens (High recommended for DeepSeek)"
|
| 65 |
-
),
|
| 66 |
-
gr.Slider(
|
| 67 |
-
minimum=0.1,
|
| 68 |
-
maximum=2.0,
|
| 69 |
-
value=0.6,
|
| 70 |
-
step=0.1,
|
| 71 |
-
label="Temperature"
|
| 72 |
-
),
|
| 73 |
-
gr.Slider(
|
| 74 |
-
minimum=0.1,
|
| 75 |
-
maximum=1.0,
|
| 76 |
-
value=0.9,
|
| 77 |
-
step=0.05,
|
| 78 |
-
label="Top-p (nucleus sampling)",
|
| 79 |
-
),
|
| 80 |
-
],
|
| 81 |
-
)
|
| 82 |
|
| 83 |
-
#
|
| 84 |
-
with gr.Blocks(theme=gr.themes.
|
|
|
|
|
|
|
| 85 |
with gr.Sidebar():
|
| 86 |
-
gr.Markdown("### Authentication")
|
| 87 |
gr.LoginButton()
|
| 88 |
-
gr.Markdown(
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
)
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
| 96 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
MODEL_ID = "Qwen/Qwen2.5-Coder-32B-Instruct"
|
| 5 |
+
|
| 6 |
+
# Tailored system prompt for a fellow modder
|
| 7 |
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, hf_token: gr.OAuthToken):
|
| 55 |
+
client = InferenceClient(token=hf_token.token if hf_token else None, model=MODEL_ID)
|
| 56 |
+
|
| 57 |
messages = [{"role": "system", "content": system_message}]
|
| 58 |
+
for val in history:
|
| 59 |
+
if val[0]: messages.append({"role": "user", "content": val[0]})
|
| 60 |
+
if val[1]: messages.append({"role": "assistant", "content": val[1]})
|
| 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, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)}. Check if your HF Token is valid or if the model is currently loading."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
# Gradio Interface
|
| 76 |
+
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
| 77 |
+
gr.Markdown("# 🛠️ Minecraft Modding Log Analyzer")
|
| 78 |
+
|
| 79 |
with gr.Sidebar():
|
|
|
|
| 80 |
gr.LoginButton()
|
| 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 (Keep low for logs)")
|
| 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 |
demo.launch()
|