mgokg commited on
Commit
e5d9b98
·
verified ·
1 Parent(s): fe64d79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -7,7 +7,7 @@ import json
7
  import csv
8
 
9
  # Load environment variables
10
- api_key = os.environ.get('groq')
11
  read_key = os.environ.get('HF_TOKEN', None)
12
 
13
  # Initialize Groq client
@@ -77,7 +77,6 @@ def parse_links_and_content(ort):
77
 
78
  return all_links_text, all_links
79
 
80
-
81
  def extract_vereinsname(url):
82
  parts = url.split('/')
83
  vereinsname = parts[-1]
@@ -92,8 +91,6 @@ def scrape_links(links):
92
  soup = BeautifulSoup(response.content, 'html.parser')
93
  target_nav = soup.select_one('.nav')
94
  parts = link.split('/')
95
- #vereinsname = parts[-1]
96
- #vereinsname = parts[4]
97
  if target_nav:
98
  details.append(f"Verein: {parts[-1]} {target_nav.text.strip()}")
99
  else:
@@ -101,8 +98,7 @@ def scrape_links(links):
101
  except Exception as e:
102
  details.append(f"Error: {str(e)}")
103
 
104
- #json_data = json.dumps(details, indent=4)
105
- return json_data
106
 
107
  def save_to_csv(data, filename):
108
  keys = data[0].keys() if data else []
@@ -111,11 +107,9 @@ def save_to_csv(data, filename):
111
  dict_writer.writeheader()
112
  dict_writer.writerows(data)
113
 
114
- #clear output
115
  def clear():
116
- clear=""
117
- return clear
118
-
119
 
120
  # Create the Gradio interface
121
  with gr.Blocks() as demo:
@@ -133,14 +127,13 @@ with gr.Blocks() as demo:
133
  save_to_csv(json_data, './contact_details.csv')
134
  return links_text, contact_details
135
 
136
- # Button to start the
137
-
138
  with gr.Row():
139
- clearbutton = gr.Button("clear")
140
- button = gr.Button("senden")
141
 
142
  # Connect the button to the function
143
  button.click(fn=process_ort, inputs=ort_input, outputs=[links_output, details_output])
144
- clearbutton.click(fn=clear, inputs=[], outputs=links_output)
 
145
  # Launch the Gradio application
146
  demo.launch()
 
7
  import csv
8
 
9
  # Load environment variables
10
+ api_key = os.environ.get('GROQ_API_KEY')
11
  read_key = os.environ.get('HF_TOKEN', None)
12
 
13
  # Initialize Groq client
 
77
 
78
  return all_links_text, all_links
79
 
 
80
  def extract_vereinsname(url):
81
  parts = url.split('/')
82
  vereinsname = parts[-1]
 
91
  soup = BeautifulSoup(response.content, 'html.parser')
92
  target_nav = soup.select_one('.nav')
93
  parts = link.split('/')
 
 
94
  if target_nav:
95
  details.append(f"Verein: {parts[-1]} {target_nav.text.strip()}")
96
  else:
 
98
  except Exception as e:
99
  details.append(f"Error: {str(e)}")
100
 
101
+ return details
 
102
 
103
  def save_to_csv(data, filename):
104
  keys = data[0].keys() if data else []
 
107
  dict_writer.writeheader()
108
  dict_writer.writerows(data)
109
 
110
+ # Clear output
111
  def clear():
112
+ return "", ""
 
 
113
 
114
  # Create the Gradio interface
115
  with gr.Blocks() as demo:
 
127
  save_to_csv(json_data, './contact_details.csv')
128
  return links_text, contact_details
129
 
 
 
130
  with gr.Row():
131
+ clearbutton = gr.Button("Clear")
132
+ button = gr.Button("Senden")
133
 
134
  # Connect the button to the function
135
  button.click(fn=process_ort, inputs=ort_input, outputs=[links_output, details_output])
136
+ clearbutton.click(fn=clear, inputs=[], outputs=[links_output, details_output])
137
+
138
  # Launch the Gradio application
139
  demo.launch()