Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,29 +10,34 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
10 |
## paramas
|
11 |
|
12 |
def fit_text(text:str):
|
13 |
-
##
|
14 |
-
system_prompt = '
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
messages = [
|
20 |
{'role': 'system', 'content': system_prompt},
|
21 |
{'role': 'user', 'content': user_prompt}
|
22 |
-
|
23 |
|
24 |
-
## Using ChatGPT for
|
25 |
response = openai.ChatCompletion.create(
|
26 |
model='gpt-3.5-turbo',
|
27 |
messages=messages,
|
28 |
temperature=0.7,
|
29 |
max_tokens=1000,
|
30 |
-
|
31 |
|
32 |
response = response['choices'][0]['message']['content']
|
33 |
|
34 |
return response
|
35 |
|
|
|
36 |
def generate_image(description:str):
|
37 |
response = openai.Image.create(
|
38 |
prompt=description, ## The description for the image
|
|
|
10 |
## paramas
|
11 |
|
12 |
def fit_text(text:str):
|
13 |
+
## Optimized system prompt
|
14 |
+
system_prompt = 'Generate an image based on the provided description.'
|
15 |
+
|
16 |
+
user_prompt = f'''Given the input text "{text}", please generate an image that embodies the following characteristics:
|
17 |
+
- Clear and detailed representation
|
18 |
+
- Relevant to the provided description
|
19 |
+
- Incorporating key elements and context
|
20 |
+
- Creative and visually appealing'''
|
21 |
+
|
22 |
+
## Messages
|
23 |
messages = [
|
24 |
{'role': 'system', 'content': system_prompt},
|
25 |
{'role': 'user', 'content': user_prompt}
|
26 |
+
]
|
27 |
|
28 |
+
## Using ChatGPT for Chat Completion
|
29 |
response = openai.ChatCompletion.create(
|
30 |
model='gpt-3.5-turbo',
|
31 |
messages=messages,
|
32 |
temperature=0.7,
|
33 |
max_tokens=1000,
|
34 |
+
)
|
35 |
|
36 |
response = response['choices'][0]['message']['content']
|
37 |
|
38 |
return response
|
39 |
|
40 |
+
|
41 |
def generate_image(description:str):
|
42 |
response = openai.Image.create(
|
43 |
prompt=description, ## The description for the image
|