Spaces:
Paused
Paused
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -31,23 +31,6 @@ model = PeftModel.from_pretrained(model, LORA_MODEL, token=HF_TOKEN)
|
|
| 31 |
model.eval()
|
| 32 |
print("Model loaded!")
|
| 33 |
|
| 34 |
-
def extract_json(text):
|
| 35 |
-
json_match = re.search(r'```(?:json)?\s*([\s\S]*?)\s*```', text)
|
| 36 |
-
if json_match:
|
| 37 |
-
try:
|
| 38 |
-
parsed = json.loads(json_match.group(1))
|
| 39 |
-
return json.dumps(parsed, indent=2, ensure_ascii=False)
|
| 40 |
-
except:
|
| 41 |
-
return json_match.group(1)
|
| 42 |
-
json_match = re.search(r'(\{[\s\S]*\})', text)
|
| 43 |
-
if json_match:
|
| 44 |
-
try:
|
| 45 |
-
parsed = json.loads(json_match.group(1))
|
| 46 |
-
return json.dumps(parsed, indent=2, ensure_ascii=False)
|
| 47 |
-
except:
|
| 48 |
-
pass
|
| 49 |
-
return ""
|
| 50 |
-
|
| 51 |
def respond(message, history):
|
| 52 |
messages = [{"role": "system", "content": "Du bist Zurd n8n Builder. Generiere n8n Workflow JSON in ```json Code-Bloecken."}]
|
| 53 |
for h in history:
|
|
@@ -68,31 +51,18 @@ def respond(message, history):
|
|
| 68 |
pad_token_id=tokenizer.eos_token_id
|
| 69 |
)
|
| 70 |
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 71 |
-
|
| 72 |
-
return response, json_code
|
| 73 |
-
|
| 74 |
-
with gr.Blocks(title="Zurd n8n Builder", theme=gr.themes.Soft(primary_hue="orange")) as demo:
|
| 75 |
-
gr.Markdown("# Zurd n8n Builder\nKI-Assistent fuer n8n Workflow Automatisierung")
|
| 76 |
-
|
| 77 |
-
with gr.Row():
|
| 78 |
-
with gr.Column():
|
| 79 |
-
chatbot = gr.Chatbot(height=400, label="Chat")
|
| 80 |
-
msg = gr.Textbox(placeholder="Beschreibe deinen Workflow...", label="Nachricht")
|
| 81 |
-
with gr.Row():
|
| 82 |
-
submit = gr.Button("Senden", variant="primary")
|
| 83 |
-
clear = gr.Button("Leeren")
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
clear.click(lambda: ([], ""), outputs=[chatbot, json_output])
|
| 97 |
|
| 98 |
demo.launch()
|
|
|
|
| 31 |
model.eval()
|
| 32 |
print("Model loaded!")
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def respond(message, history):
|
| 35 |
messages = [{"role": "system", "content": "Du bist Zurd n8n Builder. Generiere n8n Workflow JSON in ```json Code-Bloecken."}]
|
| 36 |
for h in history:
|
|
|
|
| 51 |
pad_token_id=tokenizer.eos_token_id
|
| 52 |
)
|
| 53 |
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 54 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
demo = gr.ChatInterface(
|
| 57 |
+
respond,
|
| 58 |
+
title="Zurd n8n Builder",
|
| 59 |
+
description="KI-Assistent fuer n8n Workflow Automatisierung. Beschreibe deinen gewuenschten Workflow und erhalte n8n JSON.",
|
| 60 |
+
examples=[
|
| 61 |
+
"Erstelle einen Workflow der taeglich eine E-Mail mit dem Wetter sendet",
|
| 62 |
+
"Automatisierung: GitHub Issues -> Slack Benachrichtigung",
|
| 63 |
+
"API Daten abrufen und in Google Sheets speichern"
|
| 64 |
+
],
|
| 65 |
+
theme=gr.themes.Soft(primary_hue="orange")
|
| 66 |
+
)
|
|
|
|
| 67 |
|
| 68 |
demo.launch()
|