-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.jsx
33 lines (28 loc) · 958 Bytes
/
App.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { useState } from 'react';
import { Configuration, OpenAIApi } from 'openai'
import './App.css';
function App() {
const [prompt, setPrompt] = useState("");
const [result, setResult] = useState('');
const configuration = new Configuration({
apiKey: import.meta.env.VITE_Open_AI_Key,
});
const openai = new OpenAIApi(configuration);
const generateImage = async () => {
const res = await openai.createImage({
prompt: prompt,
n: 1,
size: "1024x1024",
});
setResult(res.data.data[0].url);
}
return <div className="app-main">
<h3>Generate an Image By Using OpenAI API</h3>
<input className="app-input"
placeholder="Type the description for Image..."
onChange={(e) => setPrompt(e.target.value)}/>
<button onClick={generateImage}>Generate the Image Bitch</button>
{result.length>0 ? <img className="result-image" src={result} alt="" /> : <></>}
</div>;
}
export default App;