Spaces:
Runtime error
Runtime error
qwen
Browse files
app.py
CHANGED
|
@@ -3,11 +3,10 @@ from huggingface_hub import InferenceClient
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
# Securely retrieve the token from your Space secrets
|
| 6 |
-
# Ensure you have a secret named HF_TOKEN in your Settings
|
| 7 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
client = InferenceClient("
|
| 11 |
|
| 12 |
class StateController:
|
| 13 |
def __init__(self):
|
|
@@ -44,9 +43,9 @@ def generate_response(message, history):
|
|
| 44 |
output = "Diagnostic sequence initiated.\n\n"
|
| 45 |
output += f"{controller.initialize_grid()}\n\n"
|
| 46 |
output += "Rendering 121-point array:\n"
|
| 47 |
-
output += f"
|
| 48 |
output += "Executing state resolution:\n"
|
| 49 |
-
output += f"
|
| 50 |
return output
|
| 51 |
|
| 52 |
system_instruction = (
|
|
@@ -55,35 +54,40 @@ def generate_response(message, history):
|
|
| 55 |
"Provide direct, technical, and accurate responses."
|
| 56 |
)
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
-
for
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
formatted_messages.append({"role": "user", "content": message})
|
| 64 |
|
| 65 |
try:
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
)
|
| 73 |
-
return
|
| 74 |
except Exception as error:
|
| 75 |
-
return f"System Error: {str(error)}.
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
gr.Markdown("# Advanced Logic Interface")
|
| 80 |
gr.ChatInterface(
|
| 81 |
fn=generate_response,
|
| 82 |
description="Inference layer utilizing state-hold logic.",
|
| 83 |
examples=[
|
| 84 |
"Run grid diagnostic",
|
| 85 |
-
"
|
| 86 |
-
"
|
| 87 |
]
|
| 88 |
)
|
| 89 |
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
# Securely retrieve the token from your Space secrets
|
|
|
|
| 6 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
|
| 8 |
+
# Initializing with a model that has high serverless availability
|
| 9 |
+
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=HF_TOKEN)
|
| 10 |
|
| 11 |
class StateController:
|
| 12 |
def __init__(self):
|
|
|
|
| 43 |
output = "Diagnostic sequence initiated.\n\n"
|
| 44 |
output += f"{controller.initialize_grid()}\n\n"
|
| 45 |
output += "Rendering 121-point array:\n"
|
| 46 |
+
output += f"{controller.render_grid()}\n\n"
|
| 47 |
output += "Executing state resolution:\n"
|
| 48 |
+
output += f"{controller.resolve_grid()}"
|
| 49 |
return output
|
| 50 |
|
| 51 |
system_instruction = (
|
|
|
|
| 54 |
"Provide direct, technical, and accurate responses."
|
| 55 |
)
|
| 56 |
|
| 57 |
+
# Building the prompt for the text generation API
|
| 58 |
+
prompt = f"<|im_start|>system\n{system_instruction}<|im_end|>\n"
|
| 59 |
+
for user_msg, assistant_msg in history:
|
| 60 |
+
prompt += f"<|im_start|>user\n{user_msg}<|im_end|>\n<|im_start|>assistant\n{assistant_msg}<|im_end|>\n"
|
| 61 |
+
prompt += f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
|
|
|
|
| 62 |
|
| 63 |
try:
|
| 64 |
+
# Using text_generation for direct inference API access
|
| 65 |
+
response = client.text_generation(
|
| 66 |
+
prompt,
|
| 67 |
+
max_new_tokens=1024,
|
| 68 |
+
stop_sequences=["<|im_end|>", "<|endoftext|>"],
|
| 69 |
+
temperature=0.1 # Low temperature for high precision
|
| 70 |
)
|
| 71 |
+
return response.strip()
|
| 72 |
except Exception as error:
|
| 73 |
+
return f"System Error: {str(error)}. If the error persists, ensure your HF_TOKEN has Inference permissions."
|
| 74 |
|
| 75 |
+
custom_css = """
|
| 76 |
+
body, .gradio-container { background-color: #0b0f19 !important; }
|
| 77 |
+
footer {display: none !important}
|
| 78 |
+
.message.user { background-color: #1e293b !important; border: 1px solid #3b82f6 !important; }
|
| 79 |
+
.message.bot { background-color: #0f172a !important; color: #60a5fa !important; }
|
| 80 |
+
"""
|
| 81 |
+
|
| 82 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=custom_css) as demo:
|
| 83 |
gr.Markdown("# Advanced Logic Interface")
|
| 84 |
gr.ChatInterface(
|
| 85 |
fn=generate_response,
|
| 86 |
description="Inference layer utilizing state-hold logic.",
|
| 87 |
examples=[
|
| 88 |
"Run grid diagnostic",
|
| 89 |
+
"Calculate the integer distribution for 120 units across 3 nodes.",
|
| 90 |
+
"Explain network latency using technical terminology."
|
| 91 |
]
|
| 92 |
)
|
| 93 |
|