import gradio as gr import os import re from dotenv import load_dotenv from openai import OpenAI load_dotenv() client = OpenAI( base_url="https://openrouter.ai/api/v1", api_key=os.environ.get("OPENROUTER_API_KEY"), ) def clean_response(text: str) -> str: lines = [] for line in text.splitlines(): line = re.sub(r"^\s*[*#•\-]+\s*", "", line) line = re.sub(r"\*\*(.*?)\*\*", r"\1", line) # Only strip double underscores around a phrase. A single token like # __init__ is a Python dunder, which shares the exact shape of # __underline__ and cannot be told apart by position alone. line = re.sub(r"(?