import streamlit as st from dotenv import load_dotenv import requests from bs4 import BeautifulSoup from bs4 import NavigableString import openai import os import hmac from st_copy_to_clipboard import st_copy_to_clipboard load_dotenv() def create_article(length_option, articles, params, web_page_option): article_string = "; ".join(f"Artikel {index + 1}: {artikel}" for index, artikel in enumerate(articles)) if length_option == "Kurz": length = 8 elif length_option == "Mittel": length = 14 elif length_option == "Lang": length = 20 openai.api_key = os.environ.get("OPEN_API_KEY") openai.api_base = os.environ.get("OPEN_API_BASE") openai.api_type = os.environ.get("OPEN_API_TYPE") openai.api_version = os.environ.get("OPEN_API_VERSION") if web_page_option == "heute.at": writing_style = os.environ.get("WRITING_STYLE_HEUTE") else: writing_style = os.environ.get("WRITING_STYLE_GESUND") try: res = openai.ChatCompletion.create( engine="gpt-4-1106", temperature=0.4, messages=[ { "role": "system", "content": f"You are a professional journalist whose task is to write your own article based on one or more articles. This article should combine the content of the original articles, but have its own writing style, which is as follows: {writing_style} Do not use unusual phrases or neologisms from the original articles. The length of your article should be {length} sentences long.", }, { "role": "system", "content": f"Source articles: {article_string}" }, { "role": "system", "content": f"Please also note the following instructions defined by the user: {params}" }, { "role": "system", "content": "Schreibe den Artikel immer in deutscher Sprache." } ], ) return res["choices"][0]["message"]["content"] except Exception as e: print(f"Fehler beim erstellen des artikels: {str(e)}") st.error(f"Something went wrong: {str(e)}", icon="🚨") def create_headline(article, web_page_option): openai.api_key = os.environ.get("OPEN_API_KEY") openai.api_base = os.environ.get("OPEN_API_BASE") openai.api_type = os.environ.get("OPEN_API_TYPE") openai.api_version = os.environ.get("OPEN_API_VERSION") if web_page_option == "heute.at": writing_style = os.environ.get("WRITING_STYLE_HEUTE") else: writing_style = os.environ.get("WRITING_STYLE_GESUND") try: res = openai.ChatCompletion.create( engine="gpt-4-1106", temperature=0.4, messages=[ { "role": "system", "content": f"You are a professional journalist and have the task of generating a headline for an article you have written. I will give you the writing style that was used to create the article as info. Writing style: {writing_style} The headline should be as short as possible, but still capture the essence of the article. It should be a maximum of 10 words long", }, { "role": "system", "content": f"Source article: {article}" }, { "role": "system", "content": "Schreibe die Headline immer in deutscher Sprache." } ], ) return res["choices"][0]["message"]["content"] except Exception as e: print(f"Fehler beim erstellen der headline: {str(e)}") st.error(f"Something went wrong: {str(e)}", icon="🚨") def extract_text_from_element(element): # Initialisiere einen leeren Textstring text_content = "" # Überprüfe, ob das Element ein

,