Spaces:
Running
Running
Update: Tutorial教程截流-HuggingFace Space
Browse files
app.py
CHANGED
|
@@ -1,140 +1,369 @@
|
|
| 1 |
"""
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
Get your API key: https://rapidapi.com/user/nexaquency
|
| 6 |
-
Docs: https://nexa-api.com
|
| 7 |
"""
|
| 8 |
|
| 9 |
import gradio as gr
|
| 10 |
-
import os
|
| 11 |
-
import requests
|
| 12 |
-
|
| 13 |
-
# NexaAPI configuration
|
| 14 |
-
NEXAAPI_BASE_URL = "https://api.nexa-api.com/v1"
|
| 15 |
-
|
| 16 |
-
MODELS = {
|
| 17 |
-
"Flux Schnell ($0.003/image) — Fastest": "flux-schnell",
|
| 18 |
-
"Flux Pro 1.1 ($0.02/image) — Best Quality": "flux-pro-1.1",
|
| 19 |
-
"Flux Dev ($0.01/image) — Balanced": "flux-dev",
|
| 20 |
-
"Stable Diffusion 3.5 ($0.005/image)": "stable-diffusion-3.5",
|
| 21 |
-
"Stable Diffusion XL ($0.003/image)": "stable-diffusion-xl",
|
| 22 |
-
}
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
"
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
|
|
|
|
| 32 |
|
| 33 |
-
def
|
| 34 |
-
"""
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
client = OpenAI(api_key=api_key, base_url=NEXAAPI_BASE_URL)
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
size=f"{width}x{height}",
|
| 53 |
-
n=1
|
| 54 |
-
)
|
| 55 |
|
| 56 |
-
|
| 57 |
-
cost_info = f"✅ Generated! Cost: ${price:.3f} | Model: {model} | URL: {image_url}"
|
| 58 |
-
return image_url, cost_info
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
with gr.Blocks(
|
| 69 |
-
title="NexaAPI — Cheapest AI Image Generation 2026",
|
| 70 |
-
theme=gr.themes.Soft()
|
| 71 |
-
) as demo:
|
| 72 |
-
gr.Markdown("""
|
| 73 |
-
# 🚀 NexaAPI — Cheapest AI Image Generation Demo
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
""")
|
| 81 |
|
| 82 |
-
with gr.Row():
|
| 83 |
-
with gr.Column(scale=1):
|
| 84 |
-
api_key = gr.Textbox(
|
| 85 |
-
label="NexaAPI Key",
|
| 86 |
-
placeholder="Enter your API key from RapidAPI",
|
| 87 |
-
type="password"
|
| 88 |
-
)
|
| 89 |
-
prompt = gr.Textbox(
|
| 90 |
-
label="Prompt",
|
| 91 |
-
placeholder="A red panda coding at a computer, digital art style",
|
| 92 |
-
lines=3,
|
| 93 |
-
value="A red panda coding at a computer, digital art style"
|
| 94 |
-
)
|
| 95 |
-
model_select = gr.Dropdown(
|
| 96 |
-
label="Model",
|
| 97 |
-
choices=list(MODELS.keys()),
|
| 98 |
-
value="Flux Schnell ($0.003/image) — Fastest"
|
| 99 |
-
)
|
| 100 |
-
with gr.Row():
|
| 101 |
-
width = gr.Slider(512, 1024, value=1024, step=64, label="Width")
|
| 102 |
-
height = gr.Slider(512, 1024, value=1024, step=64, label="Height")
|
| 103 |
-
generate_btn = gr.Button("🎨 Generate Image", variant="primary")
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
outputs=[output_image, cost_display]
|
| 113 |
-
)
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
gr.Markdown("""
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
##
|
| 126 |
-
|
| 127 |
-
|
|
| 128 |
-
|
|
| 129 |
-
|
|
| 130 |
-
|
|
| 131 |
-
|
|
| 132 |
-
|
| 133 |
-
**Links:**
|
| 134 |
-
- 🌐 [nexa-api.com](https://nexa-api.com)
|
| 135 |
-
- 🚀 [RapidAPI Hub](https://rapidapi.com/user/nexaquency)
|
| 136 |
-
- 🐍 [pip install nexaapi](https://pypi.org/project/nexaapi/)
|
| 137 |
-
- 📦 [npm install nexaapi](https://www.npmjs.com/package/nexaapi)
|
| 138 |
""")
|
| 139 |
|
| 140 |
if __name__ == "__main__":
|
|
|
|
| 1 |
"""
|
| 2 |
+
AI API Playground 2026 — NexaAPI Interactive Demo
|
| 3 |
+
Tabs: Image Generation | Text/LLM | Text-to-Speech | Cost Calculator
|
|
|
|
|
|
|
|
|
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# ─── Cost Calculator Data ───────────────────────────────────────────────────
|
| 9 |
+
|
| 10 |
+
PRICING = {
|
| 11 |
+
"Image Generation (per image)": {
|
| 12 |
+
"NexaAPI 🏆": 0.003,
|
| 13 |
+
"OpenAI DALL-E 3": 0.040,
|
| 14 |
+
"Stability AI": 0.020,
|
| 15 |
+
"Replicate": 0.015,
|
| 16 |
+
"FAL.ai": 0.012,
|
| 17 |
+
},
|
| 18 |
+
"LLM (per 1M tokens)": {
|
| 19 |
+
"NexaAPI 🏆": 0.50,
|
| 20 |
+
"OpenAI GPT-4o": 5.00,
|
| 21 |
+
"Anthropic Claude 3.5": 3.00,
|
| 22 |
+
"Google Gemini 1.5 Pro": 3.50,
|
| 23 |
+
"Together AI": 1.00,
|
| 24 |
+
},
|
| 25 |
+
"Text-to-Speech (per 1M chars)": {
|
| 26 |
+
"NexaAPI 🏆": 1.00,
|
| 27 |
+
"ElevenLabs": 22.00,
|
| 28 |
+
"OpenAI TTS": 15.00,
|
| 29 |
+
"Google TTS": 4.00,
|
| 30 |
+
"Azure TTS": 4.00,
|
| 31 |
+
},
|
| 32 |
}
|
| 33 |
|
| 34 |
+
# ─── Tab Functions ───────────────────────────────────────────────────────────
|
| 35 |
|
| 36 |
+
def show_image_demo(prompt, style):
|
| 37 |
+
"""Show image generation demo with code."""
|
| 38 |
+
styles = {
|
| 39 |
+
"Photorealistic": "photorealistic, 8k, detailed",
|
| 40 |
+
"Anime": "anime style, vibrant colors",
|
| 41 |
+
"Oil Painting": "oil painting, classical art style",
|
| 42 |
+
"Watercolor": "watercolor painting, soft colors",
|
| 43 |
+
}
|
| 44 |
+
style_suffix = styles.get(style, "")
|
| 45 |
+
full_prompt = f"{prompt}, {style_suffix}" if style_suffix else prompt
|
| 46 |
+
|
| 47 |
+
code = f'''```python
|
| 48 |
+
import nexaapi
|
| 49 |
|
| 50 |
+
# Image Generation — $0.003/image (13x cheaper than DALL-E 3!)
|
| 51 |
+
client = nexaapi.Client(api_key="YOUR_API_KEY")
|
| 52 |
|
| 53 |
+
result = client.image.generate(
|
| 54 |
+
prompt="{full_prompt}",
|
| 55 |
+
model="flux-schnell", # or stable-diffusion-xl, flux-pro
|
| 56 |
+
width=1024,
|
| 57 |
+
height=1024,
|
| 58 |
+
steps=4
|
| 59 |
+
)
|
| 60 |
|
| 61 |
+
# Save the image
|
| 62 |
+
with open("output.png", "wb") as f:
|
| 63 |
+
f.write(result.image_bytes)
|
|
|
|
| 64 |
|
| 65 |
+
print(f"Generated! Cost: $0.003")
|
| 66 |
+
print(f"URL: {{result.url}}")
|
| 67 |
+
```
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
**vs OpenAI DALL-E 3**: Same quality, 13x cheaper ($0.003 vs $0.04)
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
### 📊 Cost for 1,000 images:
|
| 72 |
+
- **NexaAPI**: $3.00 ✅
|
| 73 |
+
- OpenAI DALL-E 3: $40.00 ❌
|
| 74 |
+
- Stability AI: $20.00 ❌
|
| 75 |
+
- FAL.ai: $12.00 ❌
|
| 76 |
|
| 77 |
+
### 🔗 Get Started Free
|
| 78 |
+
- [nexa-api.com](https://nexa-api.com) — 100 free images, no credit card!
|
| 79 |
+
- [pip install nexaapi](https://pypi.org/project/nexaapi)
|
| 80 |
+
'''
|
| 81 |
+
|
| 82 |
+
preview = f"""
|
| 83 |
+
### 🖼️ Your Prompt
|
| 84 |
+
**"{full_prompt}"**
|
| 85 |
|
| 86 |
+
This would generate a high-quality image using NexaAPI's FLUX or Stable Diffusion models.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
+
**Cost**: $0.003 per image
|
| 89 |
+
**Speed**: ~2-4 seconds
|
| 90 |
+
**Resolution**: Up to 2048×2048
|
| 91 |
|
| 92 |
+
*Note: This is a demo playground. Sign up at [nexa-api.com](https://nexa-api.com) to generate real images!*
|
| 93 |
+
"""
|
| 94 |
+
return preview, code
|
|
|
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
def show_llm_demo(prompt, model):
|
| 98 |
+
"""Show LLM demo with code."""
|
| 99 |
+
models_info = {
|
| 100 |
+
"Claude 3.5 Sonnet": ("claude-3-5-sonnet", "$0.50/1M tokens"),
|
| 101 |
+
"GPT-4o": ("gpt-4o", "$0.50/1M tokens"),
|
| 102 |
+
"Gemini 1.5 Pro": ("gemini-1.5-pro", "$0.50/1M tokens"),
|
| 103 |
+
"Llama 3.1 70B": ("llama-3.1-70b", "$0.30/1M tokens"),
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
model_id, price = models_info.get(model, ("claude-3-5-sonnet", "$0.50/1M tokens"))
|
| 107 |
+
|
| 108 |
+
sample_responses = {
|
| 109 |
+
"Claude 3.5 Sonnet": f"I'd be happy to help with: '{prompt}'. This is a demonstration of NexaAPI's LLM capabilities — access Claude, GPT-4o, Gemini, and 50+ more models through one unified API at the lowest prices in 2026.",
|
| 110 |
+
"GPT-4o": f"Regarding your query: '{prompt}' — NexaAPI provides access to GPT-4o and all major AI models at 90% less cost than going directly to OpenAI.",
|
| 111 |
+
"Gemini 1.5 Pro": f"Processing your request: '{prompt}' — With NexaAPI, you get Gemini 1.5 Pro access at $0.50/1M tokens vs Google's $3.50/1M tokens.",
|
| 112 |
+
"Llama 3.1 70B": f"Here's my response to '{prompt}' — Llama 3.1 70B via NexaAPI is one of the most cost-effective options for high-quality open-source LLM inference.",
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
response = sample_responses.get(model, f"Response to: {prompt}")
|
| 116 |
+
|
| 117 |
+
code = f'''```python
|
| 118 |
+
import nexaapi
|
| 119 |
+
|
| 120 |
+
# LLM — 90% cheaper than direct API access!
|
| 121 |
+
client = nexaapi.Client(api_key="YOUR_API_KEY")
|
| 122 |
+
|
| 123 |
+
response = client.chat.complete(
|
| 124 |
+
model="{model_id}",
|
| 125 |
+
messages=[
|
| 126 |
+
{{"role": "user", "content": "{prompt}"}}
|
| 127 |
+
],
|
| 128 |
+
max_tokens=1000
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
print(response.choices[0].message.content)
|
| 132 |
+
print(f"Tokens used: {{response.usage.total_tokens}}")
|
| 133 |
+
print(f"Cost: {{response.usage.total_tokens / 1_000_000 * 0.50:.6f}}")
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
**Price**: {price} (vs $5.00/1M tokens for OpenAI direct)
|
| 137 |
+
|
| 138 |
+
### 🔗 Get Started Free
|
| 139 |
+
- [nexa-api.com](https://nexa-api.com) — Free tier available!
|
| 140 |
+
- [pip install nexaapi](https://pypi.org/project/nexaapi)
|
| 141 |
+
'''
|
| 142 |
+
|
| 143 |
+
return f"**{model} Response (Demo):**\n\n{response}", code
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def show_tts_demo(text, voice):
|
| 147 |
+
"""Show TTS demo with code."""
|
| 148 |
+
voices = {
|
| 149 |
+
"Nova (Female, Warm)": "nova",
|
| 150 |
+
"Alloy (Neutral)": "alloy",
|
| 151 |
+
"Echo (Male, Deep)": "echo",
|
| 152 |
+
"Shimmer (Female, Clear)": "shimmer",
|
| 153 |
+
}
|
| 154 |
+
voice_id = voices.get(voice, "nova")
|
| 155 |
+
|
| 156 |
+
code = f'''```python
|
| 157 |
+
import nexaapi
|
| 158 |
+
|
| 159 |
+
# Text-to-Speech — 22x cheaper than ElevenLabs!
|
| 160 |
+
client = nexaapi.Client(api_key="YOUR_API_KEY")
|
| 161 |
+
|
| 162 |
+
audio = client.tts.generate(
|
| 163 |
+
text="{text[:50]}...",
|
| 164 |
+
voice="{voice_id}",
|
| 165 |
+
model="tts-1-hd",
|
| 166 |
+
speed=1.0
|
| 167 |
+
)
|
| 168 |
|
| 169 |
+
# Save audio file
|
| 170 |
+
with open("output.mp3", "wb") as f:
|
| 171 |
+
f.write(audio.audio_bytes)
|
|
|
|
|
|
|
| 172 |
|
| 173 |
+
print(f"Generated {len(text)} characters")
|
| 174 |
+
print(f"Cost: ${{len(text) / 1_000_000:.6f}}") # $1.00/1M chars
|
| 175 |
+
```
|
| 176 |
+
|
| 177 |
+
**Price**: $1.00/1M characters
|
| 178 |
+
- vs ElevenLabs: $22.00/1M chars (22x more expensive!)
|
| 179 |
+
- vs OpenAI TTS: $15.00/1M chars (15x more expensive!)
|
| 180 |
+
|
| 181 |
+
### 🔗 Get Started Free
|
| 182 |
+
- [nexa-api.com](https://nexa-api.com) — 100 free TTS generations!
|
| 183 |
+
- [pip install nexaapi](https://pypi.org/project/nexaapi)
|
| 184 |
+
'''
|
| 185 |
+
|
| 186 |
+
char_count = len(text)
|
| 187 |
+
cost = char_count / 1_000_000 * 1.00
|
| 188 |
+
elevenlabs_cost = char_count / 1_000_000 * 22.00
|
| 189 |
+
|
| 190 |
+
preview = f"""
|
| 191 |
+
### 🔊 TTS Preview
|
| 192 |
+
**Text**: "{text[:100]}{'...' if len(text) > 100 else ''}"
|
| 193 |
+
**Voice**: {voice}
|
| 194 |
+
**Characters**: {char_count:,}
|
| 195 |
+
|
| 196 |
+
**Cost with NexaAPI**: ${cost:.6f}
|
| 197 |
+
**Cost with ElevenLabs**: ${elevenlabs_cost:.6f}
|
| 198 |
+
**Your savings**: ${elevenlabs_cost - cost:.6f} (22x cheaper!)
|
| 199 |
+
|
| 200 |
+
*Note: This is a demo. Sign up at [nexa-api.com](https://nexa-api.com) to generate real audio!*
|
| 201 |
+
"""
|
| 202 |
+
return preview, code
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def calculate_costs(api_type, quantity):
|
| 206 |
+
"""Calculate and compare costs."""
|
| 207 |
+
if quantity <= 0:
|
| 208 |
+
return "Please enter a quantity > 0"
|
| 209 |
+
|
| 210 |
+
prices = PRICING.get(api_type, {})
|
| 211 |
+
if not prices:
|
| 212 |
+
return "Invalid API type"
|
| 213 |
+
|
| 214 |
+
nexa_cost = prices["NexaAPI 🏆"] * quantity
|
| 215 |
+
lines = [f"## Cost for {quantity:,} units — {api_type}\n"]
|
| 216 |
+
lines.append("| Provider | Total Cost | vs NexaAPI |")
|
| 217 |
+
lines.append("|----------|-----------|------------|")
|
| 218 |
+
|
| 219 |
+
for provider, price in sorted(prices.items(), key=lambda x: x[1]):
|
| 220 |
+
total = price * quantity
|
| 221 |
+
if provider == "NexaAPI 🏆":
|
| 222 |
+
lines.append(f"| **{provider}** | **${total:.2f}** | ✅ Best Price! |")
|
| 223 |
+
else:
|
| 224 |
+
mult = total / nexa_cost
|
| 225 |
+
lines.append(f"| {provider} | ${total:.2f} | {mult:.1f}x more expensive |")
|
| 226 |
+
|
| 227 |
+
lines.append(f"\n💡 **NexaAPI saves you ${(max(prices.values()) - prices['NexaAPI 🏆']) * quantity:.2f}** vs the most expensive provider!")
|
| 228 |
+
lines.append(f"\n🚀 [Start Free at nexa-api.com](https://nexa-api.com) — No credit card required!")
|
| 229 |
+
|
| 230 |
+
return "\n".join(lines)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
# ─── Build UI ────────────────────────────────────────────────────────────────
|
| 234 |
+
|
| 235 |
+
with gr.Blocks(
|
| 236 |
+
title="AI API Playground 2026 — NexaAPI",
|
| 237 |
+
theme=gr.themes.Soft(),
|
| 238 |
+
) as demo:
|
| 239 |
+
|
| 240 |
+
gr.Markdown("""
|
| 241 |
+
# 🚀 AI API Playground 2026
|
| 242 |
+
## Access 56+ AI Models via One API — NexaAPI
|
| 243 |
+
|
| 244 |
+
**The cheapest way to access Image Generation, LLM, TTS, and Video APIs in 2026.**
|
| 245 |
+
Start with **100 free generations** — no credit card required!
|
| 246 |
+
|
| 247 |
+
🌐 [nexa-api.com](https://nexa-api.com) | 📦 [PyPI](https://pypi.org/project/nexaapi) | 📦 [npm](https://npmjs.com/package/nexaapi) | 🔗 [RapidAPI](https://rapidapi.com/user/nexaquency)
|
| 248 |
+
""")
|
| 249 |
+
|
| 250 |
+
with gr.Tabs():
|
| 251 |
+
|
| 252 |
+
# ── Tab 1: Image Generation ──────────────────────────────────────────
|
| 253 |
+
with gr.TabItem("🖼️ Image Generation"):
|
| 254 |
+
gr.Markdown("### Generate AI Images — $0.003/image (13x cheaper than DALL-E 3!)")
|
| 255 |
+
|
| 256 |
+
with gr.Row():
|
| 257 |
+
with gr.Column():
|
| 258 |
+
img_prompt = gr.Textbox(
|
| 259 |
+
label="Image Prompt",
|
| 260 |
+
placeholder="A futuristic city at sunset with flying cars...",
|
| 261 |
+
value="A beautiful mountain landscape with aurora borealis",
|
| 262 |
+
lines=3
|
| 263 |
+
)
|
| 264 |
+
img_style = gr.Dropdown(
|
| 265 |
+
choices=["Photorealistic", "Anime", "Oil Painting", "Watercolor"],
|
| 266 |
+
value="Photorealistic",
|
| 267 |
+
label="Style"
|
| 268 |
+
)
|
| 269 |
+
img_btn = gr.Button("🎨 Generate Code & Preview", variant="primary")
|
| 270 |
+
|
| 271 |
+
with gr.Column():
|
| 272 |
+
img_preview = gr.Markdown(label="Preview")
|
| 273 |
+
img_code = gr.Markdown(label="Code Example")
|
| 274 |
+
|
| 275 |
+
img_btn.click(show_image_demo, inputs=[img_prompt, img_style], outputs=[img_preview, img_code])
|
| 276 |
+
|
| 277 |
+
# ── Tab 2: LLM / Text ────────────────────────────────────────────────
|
| 278 |
+
with gr.TabItem("💬 LLM / Text"):
|
| 279 |
+
gr.Markdown("### Access 20+ LLM Models — From $0.30/1M tokens (10x cheaper than GPT-4o!)")
|
| 280 |
+
|
| 281 |
+
with gr.Row():
|
| 282 |
+
with gr.Column():
|
| 283 |
+
llm_prompt = gr.Textbox(
|
| 284 |
+
label="Your Prompt",
|
| 285 |
+
placeholder="Explain quantum computing in simple terms...",
|
| 286 |
+
value="What are the key advantages of using NexaAPI for AI development?",
|
| 287 |
+
lines=4
|
| 288 |
+
)
|
| 289 |
+
llm_model = gr.Dropdown(
|
| 290 |
+
choices=["Claude 3.5 Sonnet", "GPT-4o", "Gemini 1.5 Pro", "Llama 3.1 70B"],
|
| 291 |
+
value="Claude 3.5 Sonnet",
|
| 292 |
+
label="Model"
|
| 293 |
+
)
|
| 294 |
+
llm_btn = gr.Button("🤖 Generate Response & Code", variant="primary")
|
| 295 |
+
|
| 296 |
+
with gr.Column():
|
| 297 |
+
llm_response = gr.Markdown(label="Response Preview")
|
| 298 |
+
llm_code = gr.Markdown(label="Code Example")
|
| 299 |
+
|
| 300 |
+
llm_btn.click(show_llm_demo, inputs=[llm_prompt, llm_model], outputs=[llm_response, llm_code])
|
| 301 |
+
|
| 302 |
+
# ── Tab 3: TTS ───────────────────────────────────────────────────────
|
| 303 |
+
with gr.TabItem("🔊 Text-to-Speech"):
|
| 304 |
+
gr.Markdown("### Convert Text to Speech — $1.00/1M chars (22x cheaper than ElevenLabs!)")
|
| 305 |
+
|
| 306 |
+
with gr.Row():
|
| 307 |
+
with gr.Column():
|
| 308 |
+
tts_text = gr.Textbox(
|
| 309 |
+
label="Text to Convert",
|
| 310 |
+
placeholder="Enter text to convert to speech...",
|
| 311 |
+
value="Welcome to NexaAPI — the most affordable AI API platform in 2026. Access 56 models including Claude, GPT-4o, Gemini, FLUX, and more.",
|
| 312 |
+
lines=4
|
| 313 |
+
)
|
| 314 |
+
tts_voice = gr.Dropdown(
|
| 315 |
+
choices=["Nova (Female, Warm)", "Alloy (Neutral)", "Echo (Male, Deep)", "Shimmer (Female, Clear)"],
|
| 316 |
+
value="Nova (Female, Warm)",
|
| 317 |
+
label="Voice"
|
| 318 |
+
)
|
| 319 |
+
tts_btn = gr.Button("🎙️ Generate Code & Preview", variant="primary")
|
| 320 |
+
|
| 321 |
+
with gr.Column():
|
| 322 |
+
tts_preview = gr.Markdown(label="Preview")
|
| 323 |
+
tts_code = gr.Markdown(label="Code Example")
|
| 324 |
+
|
| 325 |
+
tts_btn.click(show_tts_demo, inputs=[tts_text, tts_voice], outputs=[tts_preview, tts_code])
|
| 326 |
+
|
| 327 |
+
# ── Tab 4: Cost Calculator ───────────────────────────────────────────
|
| 328 |
+
with gr.TabItem("💰 Cost Calculator"):
|
| 329 |
+
gr.Markdown("### Calculate Your Savings — See How Much You Overpay with Other Providers")
|
| 330 |
+
|
| 331 |
+
with gr.Row():
|
| 332 |
+
with gr.Column(scale=1):
|
| 333 |
+
calc_api = gr.Dropdown(
|
| 334 |
+
choices=list(PRICING.keys()),
|
| 335 |
+
value="Image Generation (per image)",
|
| 336 |
+
label="API Type"
|
| 337 |
+
)
|
| 338 |
+
calc_qty = gr.Number(
|
| 339 |
+
value=10000,
|
| 340 |
+
label="Monthly Usage (units)",
|
| 341 |
+
minimum=1
|
| 342 |
+
)
|
| 343 |
+
calc_btn = gr.Button("💰 Calculate Costs", variant="primary")
|
| 344 |
+
|
| 345 |
+
with gr.Column(scale=2):
|
| 346 |
+
calc_results = gr.Markdown(label="Cost Comparison")
|
| 347 |
+
|
| 348 |
+
calc_btn.click(calculate_costs, inputs=[calc_api, calc_qty], outputs=[calc_results])
|
| 349 |
+
|
| 350 |
gr.Markdown("""
|
| 351 |
+
---
|
| 352 |
+
## 🏆 Why NexaAPI?
|
| 353 |
+
|
| 354 |
+
- **56+ Models**: Claude, GPT-4o, Gemini, FLUX, Stable Diffusion, Kling, Sora alternatives & more
|
| 355 |
+
- **Lowest Prices**: Up to 95% cheaper than going directly to model providers
|
| 356 |
+
- **One API**: OpenAI-compatible — works with your existing code
|
| 357 |
+
- **Free Tier**: 100 free generations, no credit card required
|
| 358 |
+
- **Fast**: Global CDN, <100ms latency
|
| 359 |
+
|
| 360 |
+
### 🔗 Get Started Now
|
| 361 |
+
| Platform | Link |
|
| 362 |
+
|----------|------|
|
| 363 |
+
| 🌐 Website | [nexa-api.com](https://nexa-api.com) |
|
| 364 |
+
| 🐍 Python | [pip install nexaapi](https://pypi.org/project/nexaapi) |
|
| 365 |
+
| 📦 JavaScript | [npm install nexaapi](https://npmjs.com/package/nexaapi) |
|
| 366 |
+
| 🔗 RapidAPI | [rapidapi.com/user/nexaquency](https://rapidapi.com/user/nexaquency) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
""")
|
| 368 |
|
| 369 |
if __name__ == "__main__":
|