-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTatoo recom.py
72 lines (51 loc) · 1.79 KB
/
Tatoo recom.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import openai
import streamlit as st
from PIL import Image
import webbrowser
import pandas as pd
import random
df = pd.read_csv('SelectionTitles.csv')
text = df['Title'].to_list()
random_row = random.sample(text,5)
bott = st.button("recommend it")
if bott:
st.write(random_row)
#print(random_row)
### Load your API key
openai.api_key = os.getenv("OPENAI_API_KEY")
import requests
QUERY_URL = "https://api.openai.com/v1/images/generations"
def generate_image(prompt, model, api_key):
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
model = "image-alpha-001"
data = """
{
"""
data += f'"model": "{model}",'
data += f'"prompt": "{prompt}",'
data += """
"num_images":1,
"size":"1024x1024",
"response_format":"url"
}
"""
resp = requests.post(QUERY_URL, headers=headers, data=data)
if resp.status_code != 200:
raise ValueError("Failed to generate image")
response_text = resp.json()
return response_text['data'][0]['url']
if __name__ == '__main__':
#prompt = input("Please enter your sentence:")
#prompt = "a dragon tattoo design"
prompt = st.text_input("Please enter your sentence:", 'a tattoo design with')
api_key = "***************************************************"
model = "image-alpha-001"
image_url = generate_image(prompt, model, api_key)
result = st.button("Generate")
if result :
st.markdown(image_url)
#print(f"Image URL: {image_url}")