Spaces:
Build error
Build error
File size: 3,332 Bytes
75a7093 ce827f3 75a7093 52545e8 643949c 52545e8 3540623 643949c 75a7093 643949c ce827f3 643949c 75a7093 643949c 52545e8 643949c 52545e8 643949c 52545e8 643949c 52545e8 643949c 75a7093 ce827f3 75a7093 643949c ce827f3 643949c ce827f3 75a7093 ce827f3 643949c ce827f3 52545e8 75a7093 52545e8 75a7093 643949c 75a7093 ce827f3 75a7093 ce827f3 75a7093 643949c 75a7093 52545e8 75a7093 643949c 75a7093 643949c 75a7093 643949c 75a7093 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | import gradio as gr
import graphviz
import re
from huggingface_hub import InferenceClient
# ======================================================
# MODE GRATIS TOTAL (TANPA TOKEN / API KEY)
# ======================================================
# Kita menggunakan model "Zephyr 7B Beta".
# Model ini dikenal sangat ramah untuk akses anonim (tanpa login).
# Cukup panggil namanya, dia akan bekerja.
# ======================================================
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
def engineer_mode(deskripsi_user):
if not deskripsi_user:
return "⚠️ Mohon isi deskripsi mesin dulu.", None
# Prompt Insinyur (Disederhanakan agar Zephyr mudah mengerti)
prompt_system = """
You are a Senior Industrial Automation Engineer.
Task: Create a technical design based on the user request.
OUTPUT FORMAT (USE INDONESIAN LANGUAGE):
1. DAFTAR KOMPONEN (BOM):
- List specific real parts (Omron, Siemens, etc).
2. CARA KERJA (LOGIC):
- Step-by-step operation guide.
- Include Safety (Emergency Stop).
3. WIRING GUIDE:
- Pin-to-Pin connection guide.
4. CODE PROGRAM:
- Arduino C++ or PLC Structured Text.
- Add comments.
5. DIAGRAM BLOCK (GRAPHVIZ DOT):
- ONLY WRITE THE DOT CODE.
- Start with: digraph G {
- End with: }
- Use: rankdir=LR; node [shape=box, style="filled,rounded", fillcolor="#e1f5fe"];
"""
try:
# Mengirim pesan tanpa token (Anonymous Mode)
messages = [
{"role": "system", "content": prompt_system},
{"role": "user", "content": f"Rancang mesin ini: {deskripsi_user}"}
]
response_text = ""
# Streaming response
for message in client.chat_completion(messages, max_tokens=2048, stream=True):
token = message.choices[0].delta.content
response_text += token
# Ekstraksi Diagram
dot_code = ""
if "digraph G {" in response_text:
s = response_text.find("digraph G {")
e = response_text.rfind("}") + 1
dot_code = response_text[s:e]
else:
dot_code = 'digraph G { Error -> "Diagram Gagal"; }'
try:
src = graphviz.Source(dot_code)
output_path = src.render("diagram_output", format="png")
return response_text, output_path
except:
return response_text, None
except Exception as e:
return f"⚠️ SERVER SIBUK: Model gratisan sedang ramai. Coba tekan tombol 'Rancang' lagi dalam 5 detik.\nError: {str(e)}", None
# Tampilan UI
with gr.Blocks(theme=gr.themes.Soft()) as app:
gr.Markdown("# 🏭 AI Insinyur (Mode Gratis Tanpa Kunci)")
gr.Markdown("Menggunakan **Zephyr 7B Beta**. Tidak perlu API Key, Token, atau Login.")
with gr.Row():
inp = gr.Textbox(lines=4, label="Deskripsi Mesin", placeholder="Jelaskan mesin yang mau dibuat...")
btn = gr.Button("🚀 RANCANG (GRATIS)", variant="primary")
with gr.Row():
out_txt = gr.Markdown(label="Dokumen Teknis")
out_img = gr.Image(label="Diagram Sistem")
btn.click(engineer_mode, inputs=inp, outputs=[out_txt, out_img])
app.launch() |