mbosse99 commited on
Commit
b279245
·
1 Parent(s): d3718f9

added links a query params

Browse files
Files changed (1) hide show
  1. app.py +47 -24
app.py CHANGED
@@ -13,6 +13,8 @@ from st_copy_to_clipboard import st_copy_to_clipboard
13
 
14
  load_dotenv()
15
 
 
 
16
 
17
  def get_related_studies(article: str):
18
  with st.spinner("Extrahiere Studien..."):
@@ -46,7 +48,7 @@ def get_related_studies(article: str):
46
  st.error(f"Something went wrong: {str(e)}", icon="🚨")
47
 
48
 
49
- def get_takeaways(article : str):
50
  openai.api_key = os.environ.get("OPEN_API_KEY")
51
  openai.api_base = os.environ.get("OPEN_API_BASE")
52
  openai.api_type = os.environ.get("OPEN_API_TYPE")
@@ -63,8 +65,8 @@ def get_takeaways(article : str):
63
  "content": f" The article you have written is as follows: {article}.",
64
  },
65
  {
66
- "role": "system",
67
- "content": f"Schreibe mir zu diesen Artikel Key Takeaways nach folgenden Regeln {takeaway_query}.",
68
  },
69
  ],
70
  )
@@ -72,11 +74,9 @@ def get_takeaways(article : str):
72
  except Exception as e:
73
  print(f"Fehler beim extrahieren der Query: {str(e)}")
74
  st.error(f"Something went wrong: {str(e)}", icon="🚨")
75
-
76
-
77
 
78
-
79
- def get_faq(article : str):
80
  openai.api_key = os.environ.get("OPEN_API_KEY")
81
  openai.api_base = os.environ.get("OPEN_API_BASE")
82
  openai.api_type = os.environ.get("OPEN_API_TYPE")
@@ -94,8 +94,8 @@ def get_faq(article : str):
94
  "content": f" The article you have written is as follows: {article}.",
95
  },
96
  {
97
- "role": "system",
98
- "content": f"Schreibe mir zu diesen Artikel Frequently Asked Questions nach folgenden Regeln {faq_query}.",
99
  },
100
  ],
101
  )
@@ -104,6 +104,7 @@ def get_faq(article : str):
104
  print(f"Fehler beim extrahieren der Query: {str(e)}")
105
  st.error(f"Something went wrong: {str(e)}", icon="🚨")
106
 
 
107
  def extract_scholar_query(article: str):
108
  openai.api_key = os.environ.get("OPEN_API_KEY")
109
  openai.api_base = os.environ.get("OPEN_API_BASE")
@@ -284,10 +285,10 @@ def get_article_summary(article: str) -> str:
284
  def extract_article(url):
285
  # Webseite herunterladen
286
  headers = {
287
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
288
  }
289
  response = requests.get(url, headers=headers)
290
-
291
  # Überprüfen, ob die Anfrage erfolgreich war (Status-Code 200)
292
  if response.status_code == 200:
293
  # HTML-Inhalt parsen
@@ -365,7 +366,7 @@ def on_click_handler_generate_article(**kwargs):
365
  kwargs["length_option"],
366
  kwargs["final_articles"],
367
  kwargs["add_info"],
368
- kwargs["webpage_option"],
369
  )
370
  headline = create_headline(created_article, kwargs["webpage_option"])
371
  db_analytics_item = {
@@ -419,7 +420,11 @@ def reset_session_state():
419
  if "extracted_articles" not in st.session_state:
420
  st.session_state["extracted_articles"] = []
421
  if "article_links" not in st.session_state:
422
- st.session_state["article_links"] = []
 
 
 
 
423
  if "final_articles" not in st.session_state:
424
  st.session_state["final_articles"] = []
425
  if "process_step" not in st.session_state:
@@ -655,7 +660,11 @@ if st.session_state["function_state"]:
655
  key="add_info",
656
  )
657
  st.write("Artikellänge")
658
- st.radio("Optionen", ["Kurz", "Mittel", "Lang", "SEO", "SEO Plus"], key="length_option")
 
 
 
 
659
  st.button(
660
  "Artikel generieren",
661
  key="article_btn",
@@ -684,22 +693,28 @@ if st.session_state["function_state"]:
684
  st.write(f"- [{result['title']}]({result['link']})")
685
  else:
686
  st.write("Keine relevanten Studien gefunden.")
687
-
688
  if "takeaways" in st.session_state:
689
  st.write("Hier sind einige Takeaways die wichtig sein könnten:")
690
  st.write(st.session_state["takeaways"])
691
-
692
  if "faq" in st.session_state:
693
  st.write("Hier sind FAQs zu dem Artikel:")
694
  st.write(st.session_state["faq"])
695
-
696
  st.button(
697
  "Relevante Studien finden",
698
  on_click=get_related_studies,
699
  args=(st.session_state["generated_article"],),
700
  )
701
- st.button("Key Takeaways generieren", on_click=lambda: get_takeaways(st.session_state["generated_article"]))
702
- st.button("FAQ generieren", on_click=lambda: get_faq(st.session_state["generated_article"]))
 
 
 
 
 
 
703
 
704
  st.button(
705
  "Neuen Artikel generieren", key="reset_btn", on_click=reset_session_state
@@ -710,7 +725,9 @@ else:
710
  )
711
  st.text_area(label="Artikel input:", key="keyword_article_input")
712
  st.write("Artikellänge")
713
- st.radio("Optionen", ["Kurz", "Mittel", "Lang", "SEO", "SEO Plus"], key="length_option")
 
 
714
  st.button(
715
  "Artikel generieren",
716
  key="article_btn",
@@ -746,13 +763,19 @@ else:
746
  if "takeaways" in st.session_state:
747
  st.write("Hier sind einige Takeaways die wichtig sein könnten:")
748
  st.write(st.session_state["takeaways"])
749
-
750
  if "faq" in st.session_state:
751
  st.write("Hier sind FAQs zu dem Artikel:")
752
  st.write(st.session_state["faq"])
753
-
754
- st.button("Key Takeaways generieren", on_click=lambda: get_takeaways(st.session_state["generated_article"]))
755
- st.button("FAQ generieren", on_click=lambda: get_faq(st.session_state["generated_article"]))
 
 
 
 
 
 
756
 
757
  st.button(
758
  "Neuen Artikel generieren", key="reset_btn", on_click=reset_session_state
 
13
 
14
  load_dotenv()
15
 
16
+ st.set_page_config(initial_sidebar_state="collapsed")
17
+
18
 
19
  def get_related_studies(article: str):
20
  with st.spinner("Extrahiere Studien..."):
 
48
  st.error(f"Something went wrong: {str(e)}", icon="🚨")
49
 
50
 
51
+ def get_takeaways(article: str):
52
  openai.api_key = os.environ.get("OPEN_API_KEY")
53
  openai.api_base = os.environ.get("OPEN_API_BASE")
54
  openai.api_type = os.environ.get("OPEN_API_TYPE")
 
65
  "content": f" The article you have written is as follows: {article}.",
66
  },
67
  {
68
+ "role": "system",
69
+ "content": f"Schreibe mir zu diesen Artikel Key Takeaways nach folgenden Regeln {takeaway_query}.",
70
  },
71
  ],
72
  )
 
74
  except Exception as e:
75
  print(f"Fehler beim extrahieren der Query: {str(e)}")
76
  st.error(f"Something went wrong: {str(e)}", icon="🚨")
 
 
77
 
78
+
79
+ def get_faq(article: str):
80
  openai.api_key = os.environ.get("OPEN_API_KEY")
81
  openai.api_base = os.environ.get("OPEN_API_BASE")
82
  openai.api_type = os.environ.get("OPEN_API_TYPE")
 
94
  "content": f" The article you have written is as follows: {article}.",
95
  },
96
  {
97
+ "role": "system",
98
+ "content": f"Schreibe mir zu diesen Artikel Frequently Asked Questions nach folgenden Regeln {faq_query}.",
99
  },
100
  ],
101
  )
 
104
  print(f"Fehler beim extrahieren der Query: {str(e)}")
105
  st.error(f"Something went wrong: {str(e)}", icon="🚨")
106
 
107
+
108
  def extract_scholar_query(article: str):
109
  openai.api_key = os.environ.get("OPEN_API_KEY")
110
  openai.api_base = os.environ.get("OPEN_API_BASE")
 
285
  def extract_article(url):
286
  # Webseite herunterladen
287
  headers = {
288
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
289
  }
290
  response = requests.get(url, headers=headers)
291
+
292
  # Überprüfen, ob die Anfrage erfolgreich war (Status-Code 200)
293
  if response.status_code == 200:
294
  # HTML-Inhalt parsen
 
366
  kwargs["length_option"],
367
  kwargs["final_articles"],
368
  kwargs["add_info"],
369
+ kwargs["webpage_option"],
370
  )
371
  headline = create_headline(created_article, kwargs["webpage_option"])
372
  db_analytics_item = {
 
420
  if "extracted_articles" not in st.session_state:
421
  st.session_state["extracted_articles"] = []
422
  if "article_links" not in st.session_state:
423
+ print(st.query_params.get_all("article-links[]"))
424
+ if st.query_params.get_all("article-links[]"):
425
+ st.session_state["article_links"] = st.query_params.get_all("article-links[]")
426
+ else:
427
+ st.session_state["article_links"] = []
428
  if "final_articles" not in st.session_state:
429
  st.session_state["final_articles"] = []
430
  if "process_step" not in st.session_state:
 
660
  key="add_info",
661
  )
662
  st.write("Artikellänge")
663
+ st.radio(
664
+ "Optionen",
665
+ ["Kurz", "Mittel", "Lang", "SEO", "SEO Plus"],
666
+ key="length_option",
667
+ )
668
  st.button(
669
  "Artikel generieren",
670
  key="article_btn",
 
693
  st.write(f"- [{result['title']}]({result['link']})")
694
  else:
695
  st.write("Keine relevanten Studien gefunden.")
696
+
697
  if "takeaways" in st.session_state:
698
  st.write("Hier sind einige Takeaways die wichtig sein könnten:")
699
  st.write(st.session_state["takeaways"])
700
+
701
  if "faq" in st.session_state:
702
  st.write("Hier sind FAQs zu dem Artikel:")
703
  st.write(st.session_state["faq"])
704
+
705
  st.button(
706
  "Relevante Studien finden",
707
  on_click=get_related_studies,
708
  args=(st.session_state["generated_article"],),
709
  )
710
+ st.button(
711
+ "Key Takeaways generieren",
712
+ on_click=lambda: get_takeaways(st.session_state["generated_article"]),
713
+ )
714
+ st.button(
715
+ "FAQ generieren",
716
+ on_click=lambda: get_faq(st.session_state["generated_article"]),
717
+ )
718
 
719
  st.button(
720
  "Neuen Artikel generieren", key="reset_btn", on_click=reset_session_state
 
725
  )
726
  st.text_area(label="Artikel input:", key="keyword_article_input")
727
  st.write("Artikellänge")
728
+ st.radio(
729
+ "Optionen", ["Kurz", "Mittel", "Lang", "SEO", "SEO Plus"], key="length_option"
730
+ )
731
  st.button(
732
  "Artikel generieren",
733
  key="article_btn",
 
763
  if "takeaways" in st.session_state:
764
  st.write("Hier sind einige Takeaways die wichtig sein könnten:")
765
  st.write(st.session_state["takeaways"])
766
+
767
  if "faq" in st.session_state:
768
  st.write("Hier sind FAQs zu dem Artikel:")
769
  st.write(st.session_state["faq"])
770
+
771
+ st.button(
772
+ "Key Takeaways generieren",
773
+ on_click=lambda: get_takeaways(st.session_state["generated_article"]),
774
+ )
775
+ st.button(
776
+ "FAQ generieren",
777
+ on_click=lambda: get_faq(st.session_state["generated_article"]),
778
+ )
779
 
780
  st.button(
781
  "Neuen Artikel generieren", key="reset_btn", on_click=reset_session_state