File size: 1,485 Bytes
c0572aa 2b19671 c0572aa 1e77452 8c580b7 c0572aa 1e77452 2b19671 c0572aa 2b19671 c0572aa | 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 | import gradio as gr
from model import generate_response
from prompt import SYSTEM_PROMPT
import json
import re
def process_error(error_message: str) -> str:
"""
Main function to process the error message and return JSON response.
"""
# Build full prompt with proper ending
full_prompt = SYSTEM_PROMPT + error_message.strip() + "\nJSON Output:\n<|end|>\n<|assistant|>"
# Get raw model output
raw_output = generate_response(full_prompt)
# Extrahiere JSON aus der Antwort
json_match = re.search(r"\{.*\}", raw_output, re.DOTALL)
if json_match:
raw_output = json_match.group(0)
# Attempt to parse as JSON
try:
parsed = json.loads(raw_output)
return json.dumps(parsed, indent=2)
except json.JSONDecodeError:
# Return error message if JSON is invalid
return json.dumps({
"error": "Modell hat kein valides JSON erzeugt",
"raw_output": raw_output[:500] + "..." if len(raw_output) > 500 else raw_output
}, indent=2)
# Gradio interface
interface = gr.Interface(
fn=process_error,
inputs=gr.Textbox(lines=5, placeholder="Paste your error or stack trace here...", label="Error Message"),
outputs=gr.Textbox(label="Bugfix Suggestion (JSON)"),
title="🐛 BugFix Assistant",
description="Paste an error message or stack trace to get an explanation and fix suggestion."
)
# Launch the app
if __name__ == "__main__":
interface.launch() |