Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.

DeepSeek API for AI image generation sample code

Last updated on 2 months ago
K
karthikJunior Member
Posted 2 months ago
Here's a sample Python script to generate images using the **DeepSeek Janus-Pro API** via the **Fal.ai platform**:

### **Python Code for AI Image Generation**
python
import requests

# API endpoint for DeepSeek Janus-Pro
API_URL = "https://api.fal.ai/v1/predict"

# Your API Key (Replace with your actual API key)
API_KEY = "your_api_key_here"

# Set up headers with authentication
headers = {
 "Authorization": f"Bearer {API_KEY}",
 "Content-Type": "application/json"
}

# Define the request payload
payload = {
 "model": "fal-ai/janus",
 "inputs": {
 "prompt": "A futuristic cyberpunk city at night with neon lights",
 "num_images": 1, # Number of images to generate
 "image_size": "1024x1024" # Image resolution
 }
}

# Send the request
response = requests.post(API_URL, json=payload, headers=headers)

# Process response
if response.status_code == 200:
 result = response.json()
 image_url = result['outputs'][0]['image_url']
 print(f"Image generated successfully: {image_url}")
else:
 print(f"Error: {response.status_code} - {response.text}")


### **How to Use:**
1. **Get API Key**: Sign up at [Fal.ai](https://fal.ai/models/fal-ai/janus/api) and generate your API key.
2. **Install Dependencies**: Ensure you have requests installed:
bash
 pip install requests
 

3. **Run the Script**: Replace "your_api_key_here" with your actual API key and execute the script.

This will generate an AI image based on the given text prompt and return the image URL.
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Users Online Now
Guests Online 3
Members Online 0

Total Members: 17
Newest Member: apitech