Spaces:
Sleeping
Sleeping
added multiple sites
Browse files- app.py +43 -30
- gesundheitstrends_logo.png +0 -0
app.py
CHANGED
@@ -11,7 +11,7 @@ from st_copy_to_clipboard import st_copy_to_clipboard
|
|
11 |
|
12 |
load_dotenv()
|
13 |
|
14 |
-
def create_article(length_option, articles, params):
|
15 |
|
16 |
article_string = "; ".join(f"Artikel {index + 1}: {artikel}" for index, artikel in enumerate(articles))
|
17 |
|
@@ -27,7 +27,10 @@ def create_article(length_option, articles, params):
|
|
27 |
openai.api_type = os.environ.get("OPEN_API_TYPE")
|
28 |
openai.api_version = os.environ.get("OPEN_API_VERSION")
|
29 |
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
try:
|
33 |
res = openai.ChatCompletion.create(
|
@@ -57,13 +60,16 @@ def create_article(length_option, articles, params):
|
|
57 |
print(f"Fehler beim erstellen des artikels: {str(e)}")
|
58 |
st.error(f"Something went wrong: {str(e)}", icon="🚨")
|
59 |
|
60 |
-
def create_headline(article):
|
61 |
openai.api_key = os.environ.get("OPEN_API_KEY")
|
62 |
openai.api_base = os.environ.get("OPEN_API_BASE")
|
63 |
openai.api_type = os.environ.get("OPEN_API_TYPE")
|
64 |
openai.api_version = os.environ.get("OPEN_API_VERSION")
|
65 |
|
66 |
-
|
|
|
|
|
|
|
67 |
|
68 |
try:
|
69 |
res = openai.ChatCompletion.create(
|
@@ -177,8 +183,8 @@ def decrease_page():
|
|
177 |
|
178 |
def on_click_handler_generate_article(**kwargs):
|
179 |
with st.spinner("Generiere Artikel..."):
|
180 |
-
created_article = create_article(kwargs["length_option"],kwargs["final_articles"],kwargs["add_info"])
|
181 |
-
headline = create_headline(created_article)
|
182 |
st.session_state["generated_article"] = created_article
|
183 |
st.session_state["generated_headline"] = headline
|
184 |
if st.session_state["process_step"] < 3:
|
@@ -210,40 +216,47 @@ if "function_state" not in st.session_state:
|
|
210 |
st.session_state["function_state"] = True
|
211 |
if "generated_headline" not in st.session_state:
|
212 |
st.session_state["generated_headline"] = ""
|
|
|
|
|
213 |
|
214 |
PROCESS_STEPS = ["Artikel Extraktion","Artikel Finalisierung","Artikel Generierung","Artikel Ausgabe"]
|
215 |
|
216 |
-
def check_password():
|
217 |
-
|
218 |
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
|
239 |
|
240 |
-
if not check_password():
|
241 |
-
|
242 |
|
243 |
col1, col2 = st.columns([2, 1])
|
244 |
|
245 |
col1.title("TINA")
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
247 |
|
248 |
# with st.sidebar:
|
249 |
# st.title("Funktions Auswahl")
|
@@ -303,9 +316,9 @@ if st.session_state["function_state"]:
|
|
303 |
st.text_area("Füge weitere Informationen für den Prompt hinzu, falls nötig:",key="add_info")
|
304 |
st.write("Artikellänge")
|
305 |
st.radio("Optionen",["Kurz", "Mittel", "Lang"], key="length_option")
|
306 |
-
st.button("Artikel generieren", key="article_btn", on_click=on_click_handler_generate_article, kwargs={"length_option":st.session_state["length_option"],"final_articles":st.session_state["final_articles"],"add_info":st.session_state["add_info"]})
|
307 |
elif(st.session_state["selected_page"] == 3):
|
308 |
-
st.write(st.session_state[
|
309 |
st.write(st.session_state["generated_article"])
|
310 |
st.write("Kopieren Sie den Artikel: ")
|
311 |
st_copy_to_clipboard(st.session_state["generated_headline"]+"\n"+st.session_state["generated_article"])
|
|
|
11 |
|
12 |
load_dotenv()
|
13 |
|
14 |
+
def create_article(length_option, articles, params, web_page_option):
|
15 |
|
16 |
article_string = "; ".join(f"Artikel {index + 1}: {artikel}" for index, artikel in enumerate(articles))
|
17 |
|
|
|
27 |
openai.api_type = os.environ.get("OPEN_API_TYPE")
|
28 |
openai.api_version = os.environ.get("OPEN_API_VERSION")
|
29 |
|
30 |
+
if web_page_option == "heute.at":
|
31 |
+
writing_style = os.environ.get("WRITING_STYLE_HEUTE")
|
32 |
+
else:
|
33 |
+
writing_style = os.environ.get("WRITING_STYLE_GESUND")
|
34 |
|
35 |
try:
|
36 |
res = openai.ChatCompletion.create(
|
|
|
60 |
print(f"Fehler beim erstellen des artikels: {str(e)}")
|
61 |
st.error(f"Something went wrong: {str(e)}", icon="🚨")
|
62 |
|
63 |
+
def create_headline(article, web_page_option):
|
64 |
openai.api_key = os.environ.get("OPEN_API_KEY")
|
65 |
openai.api_base = os.environ.get("OPEN_API_BASE")
|
66 |
openai.api_type = os.environ.get("OPEN_API_TYPE")
|
67 |
openai.api_version = os.environ.get("OPEN_API_VERSION")
|
68 |
|
69 |
+
if web_page_option == "heute.at":
|
70 |
+
writing_style = os.environ.get("WRITING_STYLE_HEUTE")
|
71 |
+
else:
|
72 |
+
writing_style = os.environ.get("WRITING_STYLE_GESUND")
|
73 |
|
74 |
try:
|
75 |
res = openai.ChatCompletion.create(
|
|
|
183 |
|
184 |
def on_click_handler_generate_article(**kwargs):
|
185 |
with st.spinner("Generiere Artikel..."):
|
186 |
+
created_article = create_article(kwargs["length_option"],kwargs["final_articles"],kwargs["add_info"], kwargs["webpage_option"])
|
187 |
+
headline = create_headline(created_article, kwargs["webpage_option"])
|
188 |
st.session_state["generated_article"] = created_article
|
189 |
st.session_state["generated_headline"] = headline
|
190 |
if st.session_state["process_step"] < 3:
|
|
|
216 |
st.session_state["function_state"] = True
|
217 |
if "generated_headline" not in st.session_state:
|
218 |
st.session_state["generated_headline"] = ""
|
219 |
+
if "webpage_option" not in st.session_state:
|
220 |
+
st.session_state["webpage_option"] = "heute.at"
|
221 |
|
222 |
PROCESS_STEPS = ["Artikel Extraktion","Artikel Finalisierung","Artikel Generierung","Artikel Ausgabe"]
|
223 |
|
224 |
+
# def check_password():
|
225 |
+
# """Returns `True` if the user had the correct password."""
|
226 |
|
227 |
+
# def password_entered():
|
228 |
+
# """Checks whether a password entered by the user is correct."""
|
229 |
+
# if hmac.compare_digest(st.session_state["password"], os.environ.get("PASSWORD")):
|
230 |
+
# st.session_state["password_correct"] = True
|
231 |
+
# del st.session_state["password"] # Don't store the password.
|
232 |
+
# else:
|
233 |
+
# st.session_state["password_correct"] = False
|
234 |
|
235 |
+
# # Return True if the password is validated.
|
236 |
+
# if st.session_state.get("password_correct", False):
|
237 |
+
# return True
|
238 |
|
239 |
+
# # Show input for password.
|
240 |
+
# st.text_input(
|
241 |
+
# "Password", type="password", on_change=password_entered, key="password"
|
242 |
+
# )
|
243 |
+
# if "password_correct" in st.session_state:
|
244 |
+
# st.error("😕 Password incorrect")
|
245 |
+
# return False
|
246 |
|
247 |
|
248 |
+
# if not check_password():
|
249 |
+
# st.stop() # Do not continue if check_password is not True.
|
250 |
|
251 |
col1, col2 = st.columns([2, 1])
|
252 |
|
253 |
col1.title("TINA")
|
254 |
+
if st.session_state["webpage_option"] == "heute.at":
|
255 |
+
col2.image("heute_logo.png")
|
256 |
+
else:
|
257 |
+
col2.image("gesundheitstrends_logo.png")
|
258 |
+
|
259 |
+
st.radio("Wähle die Webseite aus für die Du einen Artikel generieren möchtest",["heute.at","gesundheitstrends.com"], key="webpage_option")
|
260 |
|
261 |
# with st.sidebar:
|
262 |
# st.title("Funktions Auswahl")
|
|
|
316 |
st.text_area("Füge weitere Informationen für den Prompt hinzu, falls nötig:",key="add_info")
|
317 |
st.write("Artikellänge")
|
318 |
st.radio("Optionen",["Kurz", "Mittel", "Lang"], key="length_option")
|
319 |
+
st.button("Artikel generieren", key="article_btn", on_click=on_click_handler_generate_article, kwargs={"length_option":st.session_state["length_option"],"final_articles":st.session_state["final_articles"],"add_info":st.session_state["add_info"], "webpage_option":st.session_state["webpage_option"]})
|
320 |
elif(st.session_state["selected_page"] == 3):
|
321 |
+
st.write(f"**{st.session_state['generated_headline']}**")
|
322 |
st.write(st.session_state["generated_article"])
|
323 |
st.write("Kopieren Sie den Artikel: ")
|
324 |
st_copy_to_clipboard(st.session_state["generated_headline"]+"\n"+st.session_state["generated_article"])
|
gesundheitstrends_logo.png
ADDED
![]() |