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()