返回提交历史
Deleted
g4f/Provider/nexra/NexraSD21.py
+0
-75
Modified
g4f/Provider/nexra/__init__.py
+0
-1
XFEstudio/gpt4free
Removed provider (g4f/Provider/nexra/NexraSD21.py)
8aa3c2cc
代码差异
2 个文件
+0
-76
@@ -1,75 +0,0 @@
1
from __future__ import annotations
2
3
import json
4
from aiohttp import ClientSession
5
from ...image import ImageResponse
6
7
from ...typing import AsyncResult, Messages
8
from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
9
10
11
class NexraSD21(AsyncGeneratorProvider, ProviderModelMixin):
12
label = "Nexra Stable Diffusion 2.1"
13
url = "https://nexra.aryahcr.cc/documentation/stable-diffusion/en"
14
api_endpoint = "https://nexra.aryahcr.cc/api/image/complements"
15
working = False
16
17
default_model = 'stablediffusion-2.1'
18
models = [default_model]
19
20
model_aliases = {
21
"sd-2.1": "stablediffusion-2.1",
22
}
23
24
@classmethod
25
def get_model(cls, model: str) -> str:
26
if model in cls.models:
27
return model
28
elif model in cls.model_aliases:
29
return cls.model_aliases[model]
30
else:
31
return cls.default_model
32
33
@classmethod
34
async def create_async_generator(
35
cls,
36
model: str,
37
messages: Messages,
38
proxy: str = None,
39
response: str = "url", # base64 or url
40
**kwargs
41
) -> AsyncResult:
42
model = cls.get_model(model)
43
44
headers = {
45
"Content-Type": "application/json",
46
}
47
async with ClientSession(headers=headers) as session:
48
# Directly use the messages as the prompt
49
data = {
50
"prompt": messages,
51
"model": model,
52
"response": response,
53
"data": {
54
"prompt_negative": "",
55
"guidance_scale": 9
56
}
57
}
58
async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response:
59
response.raise_for_status()
60
text_response = await response.text()
61
62
# Clean the response by removing unexpected characters
63
cleaned_response = text_response.strip('__')
64
65
if not cleaned_response.strip():
66
raise ValueError("Received an empty response from the server.")
67
68
try:
69
json_response = json.loads(cleaned_response)
70
image_url = json_response.get("images", [])[0]
71
# Create an ImageResponse object
72
image_response = ImageResponse(images=image_url, alt="Generated Image")
73
yield image_response
74
except json.JSONDecodeError:
75
raise ValueError("Unable to decode JSON from the received text response.")
@@ -13,6 +13,5 @@ from .NexraMidjourney import NexraMidjourney
13
13
from .NexraProdiaAI import NexraProdiaAI
14
14
from .NexraQwen import NexraQwen
15
15
from .NexraSD15 import NexraSD15
16
from .NexraSD21 import NexraSD21
17
16
from .NexraSDLora import NexraSDLora
18
17
from .NexraSDTurbo import NexraSDTurbo