mgokg commited on
Commit
c1c8a1e
·
verified ·
1 Parent(s): 0fc5918

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -5,7 +5,7 @@ from urllib.parse import urljoin
5
  from gradio_client import Client
6
  import json
7
  import csv
8
- #import pandas
9
 
10
  client = Client("mgokg/PerplexicaApi")
11
 
@@ -70,22 +70,31 @@ def scrape_links(links):
70
  contact_details.append(result)
71
 
72
  return contact_details
73
-
 
 
 
 
 
 
 
 
74
  # Erstelle die Gradio-Schnittstelle
75
  with gr.Blocks() as demo:
76
  gr.Markdown("# ")
77
  ort_input = gr.Textbox(label="Ort", placeholder="Gib den Namen des Ortes ein")
78
  #links_output = gr.Textbox(label="Ergebnisse")
79
- #links_output = gr.Dataframe(label="Ergebnisse", interactive=True)
80
- links_output = gr.JSON(label="Ergebnisse")
81
 
82
  def process_ort(ort):
83
  links = parse_links_and_content(ort)
84
- contact= scrape_links(links)
85
- #return pd.DataFrame(contact)
86
  json_data = [json.loads(item) for item in contact]
 
87
  #return contact
88
- return json_data
 
89
 
90
  # Button zum Starten der Parsung
91
  button = gr.Button("senden")
 
5
  from gradio_client import Client
6
  import json
7
  import csv
8
+ import pandas
9
 
10
  client = Client("mgokg/PerplexicaApi")
11
 
 
70
  contact_details.append(result)
71
 
72
  return contact_details
73
+
74
+ # Speichere die JSON-Daten in eine CSV-Datei
75
+ def save_to_csv(data, filename):
76
+ keys = data[0].keys()
77
+ with open(filename, 'w', newline='', encoding='utf-8') as output_file:
78
+ dict_writer = csv.DictWriter(output_file, fieldnames=keys)
79
+ dict_writer.writeheader()
80
+ dict_writer.writerows(data)
81
+
82
  # Erstelle die Gradio-Schnittstelle
83
  with gr.Blocks() as demo:
84
  gr.Markdown("# ")
85
  ort_input = gr.Textbox(label="Ort", placeholder="Gib den Namen des Ortes ein")
86
  #links_output = gr.Textbox(label="Ergebnisse")
87
+ links_output = gr.Dataframe(label="Ergebnisse", interactive=True)
88
+ #links_output = gr.JSON(label="Ergebnisse")
89
 
90
  def process_ort(ort):
91
  links = parse_links_and_content(ort)
92
+ contact= scrape_links(links)
 
93
  json_data = [json.loads(item) for item in contact]
94
+ #save_to_csv(json_data, 'contact_details.csv')
95
  #return contact
96
+ return pd.DataFrame(json_data)
97
+ #return json_data
98
 
99
  # Button zum Starten der Parsung
100
  button = gr.Button("senden")