eleeter commited on
Commit
07dd92f
·
verified ·
1 Parent(s): 7da44e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -73
app.py CHANGED
@@ -1,96 +1,93 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Constants for configuration
5
- MODEL_ID = "deepseek-ai/DeepSeek-V4-Flash"
 
6
  DEFAULT_SYSTEM_PROMPT = (
7
- "You are an expert PC troubleshooter. Analyze crash logs, GPU issues, "
8
- "and driver errors with technical precision. Provide clear, step-by-step fixes."
9
- )
10
 
11
- def respond(
12
- message,
13
- history: list[dict[str, str]],
14
- system_message,
15
- max_tokens,
16
- temperature,
17
- top_p,
18
- hf_token: gr.OAuthToken,
19
- ):
20
- """
21
- Handles the chat logic using Hugging Face Inference API with DeepSeek-V4.
22
- """
23
- # Use provided OAuth token or fall back to local environment token
24
- client = InferenceClient(
25
- token=hf_token.token if hf_token else None,
26
- model=MODEL_ID
27
- )
28
 
29
- # Construct the message payload
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  messages = [{"role": "system", "content": system_message}]
31
- messages.extend(history)
 
 
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"Error connecting to DeepSeek-V4: {str(e)}"
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
- # Assemble the UI with a Sidebar for Login
84
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
 
 
85
  with gr.Sidebar():
86
- gr.Markdown("### Authentication")
87
  gr.LoginButton()
88
- gr.Markdown(
89
- "Logging in with Hugging Face allows you to use the Inference API "
90
- "directly with your own account quota."
91
- )
92
-
93
- chatbot.render()
 
 
 
 
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()