Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| import os | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| # Utilizing the conversational task through chat_completion | |
| client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=HF_TOKEN) | |
| class StateController: | |
| def __init__(self): | |
| self.state_array = [0] * 121 | |
| self.base_metric = 60 | |
| self.batch_unit = 10 | |
| self.memory_register = {} | |
| def initialize_grid(self): | |
| for i in range(51): | |
| self.state_array[i] = {"Blocks": i // self.batch_unit, "Units": i % self.batch_unit} | |
| return "Grid initialized: 5 active blocks." | |
| def render_grid(self): | |
| grid_output = "" | |
| for i in range(121): | |
| if i == 120: | |
| grid_output += " [NODE_120] " | |
| elif i % 10 == 0: | |
| grid_output += "<" | |
| else: | |
| grid_output += "." | |
| return grid_output | |
| def resolve_grid(self): | |
| self.memory_register["STATUS"] = "RESOLVED" | |
| self.state_array = [0] * 121 | |
| return "System resolved. State array reset to zero." | |
| def generate_response(message, history): | |
| # Hardware diagnostic override | |
| if "run grid diagnostic" in message.lower(): | |
| controller = StateController() | |
| output = "Diagnostic sequence initiated.\n\n" | |
| output += f"{controller.initialize_grid()}\n\n" | |
| output += "Rendering 121-point array:\n" | |
| output += f"{controller.render_grid()}\n\n" | |
| output += "Executing state resolution:\n" | |
| output += f"{controller.resolve_grid()}" | |
| return output | |
| system_instruction = ( | |
| "You are a logic-focused inference engine. " | |
| "You utilize strict state-hold memory and parallel integer blocks. " | |
| "Provide direct, technical, and accurate responses." | |
| ) | |
| # Correct format for conversational task | |
| messages = [{"role": "system", "content": system_instruction}] | |
| for user_msg, assistant_msg in history: | |
| messages.append({"role": "user", "content": user_msg}) | |
| messages.append({"role": "assistant", "content": assistant_msg}) | |
| messages.append({"role": "user", "content": message}) | |
| try: | |
| # Switching to chat_completion for model compatibility | |
| response = client.chat_completion( | |
| messages, | |
| max_tokens=1024, | |
| stream=False | |
| ) | |
| return response.choices[0].message.content | |
| except Exception as error: | |
| return f"System Error: {str(error)}. Verify your token permissions." | |
| custom_css = """ | |
| body, .gradio-container { background-color: #0b0f19 !important; } | |
| footer {display: none !important} | |
| .message.user { background-color: #1e293b !important; border: 1px solid #3b82f6 !important; } | |
| .message.bot { background-color: #0f172a !important; color: #60a5fa !important; } | |
| """ | |
| with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=custom_css) as demo: | |
| gr.Markdown("# Advanced Logic Interface") | |
| gr.ChatInterface( | |
| fn=generate_response, | |
| description="Inference layer utilizing state-hold logic.", | |
| examples=[ | |
| "Run grid diagnostic", | |
| "Calculate the integer distribution for 120 units across 3 nodes.", | |
| "Explain network latency using technical terminology." | |
| ] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |