Spaces:
Sleeping
Sleeping
File size: 4,231 Bytes
66cae18 c25af33 058d6f0 66cae18 058d6f0 c25af33 058d6f0 c25af33 058d6f0 c25af33 66cae18 058d6f0 66cae18 058d6f0 acedc46 058d6f0 66cae18 058d6f0 66cae18 058d6f0 66cae18 058d6f0 c25af33 058d6f0 c25af33 058d6f0 c25af33 058d6f0 c25af33 058d6f0 c25af33 058d6f0 c25af33 058d6f0 66cae18 c25af33 | 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | 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()
|