DigiP-AI commited on
Commit
a03174d
·
verified ·
1 Parent(s): eb74770

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -8
app.py CHANGED
@@ -1,10 +1,37 @@
1
- from diffusers import AutoPipelineForText2Image
2
- import torch
 
3
 
4
- pipeline = AutoPipelineForText2Image.from_pretrained(
5
- "runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, use_safetensors=True
6
- ).to("cuda")
7
- prompt = "peasant and dragon combat, wood cutting style, viking era, bevel with rune"
8
 
9
- image = pipeline(prompt, num_inference_steps=25).images[0]
10
- image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import json
4
 
5
+ url = "https://nexra.aryahcr.cc/api/image/complements"
6
+ headers = {
7
+ "Content-Type": "application/json"
8
+ }
9
 
10
+ def generate_image(prompt, model):
11
+ data = {
12
+ "prompt": prompt,
13
+ "model": model,
14
+ }
15
+ try:
16
+ response = requests.post(url, headers=headers, data=json.dumps(data))
17
+ raw_response = response.text.strip()
18
+
19
+ if response.status_code == 200:
20
+ cleaned_response = raw_response.lstrip('_')
21
+ response_data = json.loads(cleaned_response)
22
+
23
+ if 'images' in response_data and isinstance(response_data['images'], list):
24
+ image_url = response_data['images'][0]
25
+ return image_url
26
+ else:
27
+ return "Error: No image data in the response."
28
+ else:
29
+ return f"Error: {response.status_code}"
30
+ except json.JSONDecodeError:
31
+ return "Error: Invalid JSON response."
32
+ except Exception as e:
33
+ return str(e)
34
+
35
+
36
+ iface = gr.Interface(fn=generate_image, inputs=[gr.Textbox(label="Enter prompt"), gr.Radio(["dalle2"], label="Select Model")], outputs="image", title="DALLE2 Generation", description="Disclaimer: This uses the Nexra API for image generation. I cannot guarantee rate limits, if you do not recieve an image please try again. I will change to use a different API soon. DALL-E 3 is not supported yet.")
37
+ iface.launch()