import gradio as gr import requests import json # ====== API BASE URL ====== NEIROST4R_BASE = { "ai_v1": "https://fenst4r.life/api/ai", "ai_v2": "https://fenst4r.life/api/ai_v2", "ai_v3": "https://fenst4r.life/api/ai_v3", "ai_v4": "http://fenst4r.life/api/ai_v4", "ai_v5": "http://fenst4r.life/api/ai_v5" } NEBLORA_BASE = { "chatgpt": "http://neblora.fenst4r.life:5400/gpt", "llama": "http://neblora.fenst4r.life:5500/llama", "draw": "http://neblora.fenst4r.life:4000/draw", "v2draw": "http://neblora.fenst4r.life:4000/v2draw", "analyze_image": "http://neblora.fenst4r.life:4848/analyze-image", "tts": "http://neblora.fenst4r.life:4949/tts", "stt": "http://neblora.fenst4r.life:5000/stt", "file": "https://fenst4r.life/api/file" } HEADERS_JSON = {"Content-Type": "application/json"} # ====== NEIROST4R CALL ====== def call_neirost4r(api_version, message, profile="friendly", flags=None): if flags is None: flags = {} url = NEIROST4R_BASE.get(api_version) if not url: return "Unknown NEIROST4R API version" headers = HEADERS_JSON.copy() # v4 и v5 требуют User-Agent if api_version in ["ai_v4", "ai_v5"]: headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" data = {"message": message, "profile": profile} if api_version in ["ai_v2", "ai_v3", "ai_v4", "ai_v5"]: data["flags"] = flags try: response = requests.post(url, headers=headers, data=json.dumps(data), timeout=600) return response.json() except Exception as e: return {"error": str(e)} # ====== NEBLORA CALL ====== def call_neblora(endpoint, text, model=None): url = NEBLORA_BASE.get(endpoint) if not url: return "Unknown Neblora endpoint" data = {"text": text} if model: data["model"] = model try: response = requests.post(url, headers=HEADERS_JSON, data=json.dumps(data), timeout=30) return response.json() except Exception as e: return {"error": str(e)} # ====== Gradio Interface ====== def generate_response(api_type, endpoint, text, profile, model, flags_json): flags = {} if flags_json.strip(): try: flags = json.loads(flags_json) except: return "Flags must be valid JSON" if api_type == "NEIROST4R": return call_neirost4r(endpoint, text, profile=profile, flags=flags) else: return call_neblora(endpoint, text, model=model) with gr.Blocks() as demo: gr.Markdown("## NEIROST4R + Neblora Unified Interface") with gr.Row(): api_type = gr.Radio(["NEIROST4R", "Neblora"], label="Выберите API") endpoint = gr.Dropdown(choices=[ "ai_v1","ai_v2","ai_v3","ai_v4","ai_v5", "chatgpt","llama","draw","v2draw","analyze_image","tts","stt","file" ], label="Endpoint / Модель") text_input = gr.Textbox(label="Введите текст", lines=4) profile_input = gr.Textbox(label="Profile (для NEIROST4R)", value="friendly") model_input = gr.Textbox(label="Model (для Neblora, если нужно)", value="") flags_input = gr.Textbox(label="Flags JSON (для NEIROST4R)", value="{}", lines=4) output = gr.JSON(label="Ответ") submit_btn = gr.Button("Отправить") submit_btn.click( generate_response, inputs=[api_type, endpoint, text_input, profile_input, model_input, flags_input], outputs=output ) # ====== Файлы ====== file_input = gr.File(label="Загрузите файлы", file_types=[".txt", ".json"]) file_url = gr.Textbox(label="Ссылка на загруженный файл") def upload_file(file): if not file: return "Нет файла" try: with open(file.name, "rb") as f: files = {"file": f} resp = requests.post(NEBLORA_BASE["file"], files=files) return resp.json() except Exception as e: return {"error": str(e)} file_btn = gr.Button("Загрузить") file_btn.click(upload_file, inputs=file_input, outputs=file_url) demo.launch()