rumaisa1054 commited on
Commit
cc03a73
·
verified ·
1 Parent(s): 263e05f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -33
app.py CHANGED
@@ -1,33 +1,15 @@
1
- import gradio as gr
2
- import requests
3
- import io
4
- import random
5
- import os
6
- from PIL import Image
7
-
8
- API_URL = "https://api-inference.huggingface.co/models/ehristoforu/dalle-3-xl"
9
- API_TOKEN = os.getenv("hugging") # it is free
10
- headers = {"Authorization": f"Bearer {API_TOKEN}"}
11
-
12
- def query(prompt, seed=None):
13
- payload = {
14
- "inputs": prompt,
15
- }
16
-
17
- image_bytes = requests.post(API_URL, headers=headers, json=payload).content
18
- image = Image.open(io.BytesIO(image_bytes))
19
- return image
20
-
21
-
22
-
23
-
24
- with gr.Blocks(theme="pseudolab/huggingface-korea-theme") as dalle:
25
- with gr.Row():
26
- image_output = gr.Image(type="pil", label="Output Image", elem_id="gallery")
27
- with gr.Column(elem_id="prompt-container"):
28
- text_prompt = gr.Textbox(label="Prompt", placeholder="a cute cat", lines=1)
29
- text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
30
-
31
- text_button.click(query, inputs=text_prompt , outputs=image_output)
32
-
33
- dalle.launch(show_api=False)
 
1
+ import streamlit as st
2
+ from openai import OpenAI
3
+ client = OpenAI(api_key = "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")
4
+ st.title("Dalle - App")
5
+ response = client.images.generate(
6
+ model="dall-e-2",
7
+ prompt="Programmer",
8
+ size="1024x1024",
9
+ quality="standard",
10
+ n=1,
11
+ )
12
+
13
+ image_url = response.data[0].url
14
+
15
+ st.markdown(image_url)