Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,16 @@ import csv
|
|
5 |
import os
|
6 |
import pandas as pd
|
7 |
import random
|
8 |
-
|
9 |
import openai
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def add_to_csv(var1, var2, var3, var4, var5, var6, var7, filename):
|
13 |
# Öffnen der CSV-Datei im Anhängemodus
|
@@ -34,6 +41,9 @@ def scrape_website(url):
|
|
34 |
return str(e)
|
35 |
|
36 |
|
|
|
|
|
|
|
37 |
def send_to_chatgpt(api_key, prompt_file, transcript):
|
38 |
try:
|
39 |
# Liest den Prompt aus der Datei
|
@@ -52,11 +62,24 @@ def send_to_chatgpt(api_key, prompt_file, transcript):
|
|
52 |
except Exception as e:
|
53 |
return str(e)
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
if st.button("Scrape"):
|
57 |
if url:
|
58 |
scraped_html = scrape_website(url)
|
59 |
response = send_to_chatgpt(api_key, base_prompt, scraped_html['scraped_html'])
|
|
|
|
|
|
|
|
|
|
|
60 |
st.code(response)
|
61 |
|
62 |
teile = response.split("Kernaussagen:")
|
@@ -78,48 +101,32 @@ if st.button("Scrape"):
|
|
78 |
else:
|
79 |
st.error("Bitte geben Sie eine gültige URL ein.")
|
80 |
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
-
|
83 |
-
token = os.getenv("token")
|
84 |
-
tokenread = os.getenv("tokenread")
|
85 |
-
localdir = "HeadlinePrediction"
|
86 |
-
repo = Repository(local_dir=localdir, clone_from="https://huggingface.co/spaces/Add1E/HeadlinePrediction", token=token)
|
87 |
-
|
88 |
-
# Beispiel für die Verwendung der Funktiona
|
89 |
-
api_key = os.getenv("api_key") # Setzen Sie hier Ihren OpenAI-API-Schlüssel ein
|
90 |
-
st.title("Webseiten-Scraper")
|
91 |
-
base_prompt = os.getenv("prompt")
|
92 |
-
csv_name = "results.csv"
|
93 |
-
df = pd.read_csv(csv_name, encoding='utf-8')
|
94 |
-
df.columns = [col.replace(' ', '_') for col in df.columns]
|
95 |
-
# Eingabefelder für URL und p_class
|
96 |
-
url = st.text_input("URL eingeben", "https://www.beispielwebsite.com")
|
97 |
-
|
98 |
-
|
99 |
-
#if st.sidebar.button("Upload Data"):
|
100 |
-
# repo.git_add(os.path.abspath(f'{localdir}/results.csv'))
|
101 |
-
# repo.git_commit("Add new headlines.csv")
|
102 |
-
# repo.git_push()
|
103 |
|
|
|
|
|
|
|
104 |
|
105 |
-
|
106 |
-
#random_numbers = set()
|
107 |
-
#while len(random_numbers) < 5:
|
108 |
-
# random_numbers.add(random.randint(0, len(df)-1))
|
109 |
|
110 |
-
#random_numbers = list(random_numbers)
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
-
#if auswahl == "Prediction 1":
|
114 |
-
# st.dataframe(df.iloc[random_numbers[0]])
|
115 |
-
#elif auswahl == "Prediction 2":
|
116 |
-
# st.dataframe(df.iloc[random_numbers[1]])
|
117 |
-
#elif auswahl == "Prediction 3":
|
118 |
-
# st.dataframe(df.iloc[random_numbers[2]])
|
119 |
-
#elif auswahl == "Prediction 4":
|
120 |
-
# st.dataframe(df.iloc[random_numbers[3]])
|
121 |
-
#elif auswahl == "Prediction 5":
|
122 |
-
# st.dataframe(df.iloc[random_numbers[4]])
|
123 |
|
124 |
|
125 |
if st.sidebar.button("Show Full Data"):
|
|
|
5 |
import os
|
6 |
import pandas as pd
|
7 |
import random
|
8 |
+
from huggingface_hub import Repository, HfApi, HfFolder
|
9 |
import openai
|
10 |
|
11 |
+
api = HfApi()
|
12 |
+
token = os.getenv("token")
|
13 |
+
tokenread = os.getenv("tokenread")
|
14 |
+
localdir = "HeadlinePrediction"
|
15 |
+
|
16 |
+
repo = Repository(local_dir=localdir, clone_from="https://huggingface.co/spaces/Add1E/HeadlinePrediction", token=token)
|
17 |
+
|
18 |
|
19 |
def add_to_csv(var1, var2, var3, var4, var5, var6, var7, filename):
|
20 |
# Öffnen der CSV-Datei im Anhängemodus
|
|
|
41 |
return str(e)
|
42 |
|
43 |
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
def send_to_chatgpt(api_key, prompt_file, transcript):
|
48 |
try:
|
49 |
# Liest den Prompt aus der Datei
|
|
|
62 |
except Exception as e:
|
63 |
return str(e)
|
64 |
|
65 |
+
st.title("Webseiten-Scraper")
|
66 |
+
base_prompt = "txt.txt"
|
67 |
+
csv_name = "results.csv"
|
68 |
+
df = pd.read_csv(csv_name, encoding='utf-8')
|
69 |
+
df.columns = [col.replace(' ', '_') for col in df.columns]
|
70 |
+
|
71 |
+
# Eingabefelder für URL und p_class
|
72 |
+
url = st.text_input("URL eingeben", "https://www.beispielwebsite.com")
|
73 |
|
74 |
if st.button("Scrape"):
|
75 |
if url:
|
76 |
scraped_html = scrape_website(url)
|
77 |
response = send_to_chatgpt(api_key, base_prompt, scraped_html['scraped_html'])
|
78 |
+
st.write("Heute-Überschrift: ")
|
79 |
+
st.code(scraped_html['heute_überschrift'])
|
80 |
+
st.write("Heute-Kernaussage: ")
|
81 |
+
st.code(scraped_html['heute_zsm'])
|
82 |
+
st.write("ChatGPT: ")
|
83 |
st.code(response)
|
84 |
|
85 |
teile = response.split("Kernaussagen:")
|
|
|
101 |
else:
|
102 |
st.error("Bitte geben Sie eine gültige URL ein.")
|
103 |
|
104 |
+
if st.sidebar.button("Upload Data"):
|
105 |
+
repo.git_add(os.path.abspath(f'{localdir}/results.csv'))
|
106 |
+
repo.git_commit("Add new headlines.csv")
|
107 |
+
repo.git_push()
|
108 |
+
|
109 |
|
110 |
+
auswahl = st.sidebar.selectbox("Wählen Sie eine Prediction:", ["None", "Prediction 1", "Prediction 2", "Prediction 3", "Prediction 4", "Prediction 5"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
+
random_numbers = set()
|
113 |
+
while len(random_numbers) < 5:
|
114 |
+
random_numbers.add(random.randint(0, len(df)-1))
|
115 |
|
116 |
+
random_numbers = list(random_numbers)
|
|
|
|
|
|
|
117 |
|
|
|
118 |
|
119 |
+
if auswahl == "Prediction 1":
|
120 |
+
st.dataframe(df.iloc[random_numbers[0]])
|
121 |
+
elif auswahl == "Prediction 2":
|
122 |
+
st.dataframe(df.iloc[random_numbers[1]])
|
123 |
+
elif auswahl == "Prediction 3":
|
124 |
+
st.dataframe(df.iloc[random_numbers[2]])
|
125 |
+
elif auswahl == "Prediction 4":
|
126 |
+
st.dataframe(df.iloc[random_numbers[3]])
|
127 |
+
elif auswahl == "Prediction 5":
|
128 |
+
st.dataframe(df.iloc[random_numbers[4]])
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
|
132 |
if st.sidebar.button("Show Full Data"):
|