Update app.py
Browse files
app.py
CHANGED
@@ -34,46 +34,63 @@ if not check_password():
|
|
34 |
st.stop() # Do not continue if check_password is not True.
|
35 |
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
41 |
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
prompt = "Please analyze a complete news article and generate a suitable DALL路E prompt in response. The prompt should provide a general overview without being overly specific and the picture should be easy to interpret. For technical purposes, please only provide the DALL路E prompt without any additional information."
|
44 |
headers = {"Authorization": f"Bearer {os.getenv('imageapi')}"}
|
45 |
url = "https://api.edenai.run/v2/image/generation"
|
46 |
|
47 |
|
48 |
article = st.text_input("Newsarticle to Image")
|
|
|
|
|
49 |
|
50 |
if st.button("Get Picture from Text"):
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
34 |
st.stop() # Do not continue if check_password is not True.
|
35 |
|
36 |
|
37 |
+
swedenclient = AzureOpenAI(
|
38 |
+
api_version = "2023-12-01-preview",
|
39 |
+
azure_endpoint = os.getenv("sweden"),
|
40 |
+
api_key = os.getenv("sweden_key"),
|
41 |
+
)
|
42 |
|
43 |
|
44 |
+
usclient = AzureOpenAI(
|
45 |
+
api_version = "2023-12-01-preview",
|
46 |
+
azure_endpoint = os.getenv("us"),
|
47 |
+
api_key = os.getenv("us_key"),
|
48 |
+
)
|
49 |
+
|
50 |
+
|
51 |
+
prompt = os.getenv("prompt")
|
52 |
+
headers = {"Authorization": f"Bearer {os.getenv('imageapi')}"}
|
53 |
+
dalle_prompt = os.getenv("dalle_prompt")
|
54 |
+
|
55 |
prompt = "Please analyze a complete news article and generate a suitable DALL路E prompt in response. The prompt should provide a general overview without being overly specific and the picture should be easy to interpret. For technical purposes, please only provide the DALL路E prompt without any additional information."
|
56 |
headers = {"Authorization": f"Bearer {os.getenv('imageapi')}"}
|
57 |
url = "https://api.edenai.run/v2/image/generation"
|
58 |
|
59 |
|
60 |
article = st.text_input("Newsarticle to Image")
|
61 |
+
pain_points = st.text_input("Pain Points for the picture")
|
62 |
+
amount_pictures = st.number_input("Anzahl Bilder", 1 , 2)
|
63 |
|
64 |
if st.button("Get Picture from Text"):
|
65 |
+
for i in range(amount_pictures):
|
66 |
+
try:
|
67 |
+
response = usclient.chat.completions.create(
|
68 |
+
model="gpt-4-0613",
|
69 |
+
temperature = 0.2,
|
70 |
+
messages=[
|
71 |
+
{"role": "system", "content": prompt + pain_points},
|
72 |
+
{"role": "system", "content": article}
|
73 |
+
],
|
74 |
+
)
|
75 |
+
except Exception as e:
|
76 |
+
st.error(f"ChatGPT Error {e}")
|
77 |
+
st.code(response.choices[0].message.content)
|
78 |
+
|
79 |
+
try:
|
80 |
+
st.code(response.choices[0].message.content + dalle_prompt)
|
81 |
+
responseimg = swedenclient.images.generate(
|
82 |
+
model="dalle-3",
|
83 |
+
prompt = response.choices[0].message.content + dalle_prompt,
|
84 |
+
n = 1
|
85 |
+
)
|
86 |
+
except Exception as e2:
|
87 |
+
st.error(f"Dall-E Error {e2}")
|
88 |
+
|
89 |
+
image_url = json.loads(responseimg.model_dump_json())['data'][0]['url']
|
90 |
+
|
91 |
+
responseimg2 = requests.get(image_url)
|
92 |
+
if responseimg2.status_code ==200:
|
93 |
+
st.image(responseimg2.content)
|
94 |
+
else:
|
95 |
+
st.error("Failed download")
|
96 |
+
|