mgokg commited on
Commit
5068324
·
verified ·
1 Parent(s): 091e5d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -4,14 +4,12 @@ from bs4 import BeautifulSoup
4
  from urllib.parse import urljoin
5
  import os
6
  import json
7
- import csv
8
  import pandas as pd
9
 
10
  # Load environment variables
11
  api_key = os.environ.get('GROQ_API_KEY')
12
  read_key = os.environ.get('HF_TOKEN', None)
13
 
14
-
15
  # Initialize Groq client
16
  if api_key:
17
  from groq import Client as GroqClient
@@ -37,7 +35,6 @@ def ask_llm(ort):
37
  return f"Error in response generation: {str(e)}"
38
 
39
  def parse_links_and_content(ort):
40
-
41
  base_url = "https://vereine-in-deutschland.net"
42
  all_links = []
43
  all_links_text = []
@@ -83,7 +80,7 @@ def parse_links_and_content(ort):
83
  def extract_vereinsname(url):
84
  parts = url.split('/')
85
  vereinsname = parts[-1]
86
- vereinsname = vereinsname.replace("-"," ")
87
  return vereinsname
88
 
89
  def scrape_links(links):
@@ -132,14 +129,13 @@ def clear():
132
  def load_data():
133
  return df
134
 
135
-
136
  # Create the Gradio interface
137
  with gr.Blocks() as demo:
138
  gr.Markdown("[![Download](https://specialist-it.de/downloadbut.png)](https://specialist-it.de/verein.csv)")
139
  with gr.Row():
140
  ort_input = gr.Textbox(label="Ort", placeholder="Gib den Namen des Ortes ein")
141
  with gr.Row():
142
- details_output = gr.TextArea(label="Ausgabe")
143
 
144
  def process_ort(ort):
145
  links_text, links = parse_links_and_content(ort)
@@ -155,16 +151,17 @@ with gr.Blocks() as demo:
155
  api_name="/model_chat"
156
  )
157
 
158
- json_data =result[1][0][1]
159
- json_data = json_data.replace("```json","")
160
- json_data = json_data.replace("```","")
161
- json_data = gr.JSON(json_data)
162
- #df = pd.read_json(json_data)
163
- #df1 = pd.DataFrame(json_data)
164
- # DataFrame in eine CSV-Datei konvertieren
165
- #df.to_csv('daten.csv', index=False)
 
166
 
167
- return json_data
168
 
169
  with gr.Row():
170
  clearbutton = gr.Button("Clear")
 
4
  from urllib.parse import urljoin
5
  import os
6
  import json
 
7
  import pandas as pd
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
14
  if api_key:
15
  from groq import Client as GroqClient
 
35
  return f"Error in response generation: {str(e)}"
36
 
37
  def parse_links_and_content(ort):
 
38
  base_url = "https://vereine-in-deutschland.net"
39
  all_links = []
40
  all_links_text = []
 
80
  def extract_vereinsname(url):
81
  parts = url.split('/')
82
  vereinsname = parts[-1]
83
+ vereinsname = vereinsname.replace("-", " ")
84
  return vereinsname
85
 
86
  def scrape_links(links):
 
129
  def load_data():
130
  return df
131
 
 
132
  # Create the Gradio interface
133
  with gr.Blocks() as demo:
134
  gr.Markdown("[![Download](https://specialist-it.de/downloadbut.png)](https://specialist-it.de/verein.csv)")
135
  with gr.Row():
136
  ort_input = gr.Textbox(label="Ort", placeholder="Gib den Namen des Ortes ein")
137
  with gr.Row():
138
+ details_output = gr.DataFrame(label="Ausgabe")
139
 
140
  def process_ort(ort):
141
  links_text, links = parse_links_and_content(ort)
 
151
  api_name="/model_chat"
152
  )
153
 
154
+ json_data = result[1][0][1]
155
+ json_data = json_data.replace("```json", "")
156
+ json_data = json_data.replace("```", "")
157
+
158
+ # Convert JSON string to Python dictionary
159
+ data_dict = json.loads(json_data)
160
+
161
+ # Convert dictionary to DataFrame
162
+ df = pd.DataFrame(data_dict)
163
 
164
+ return df
165
 
166
  with gr.Row():
167
  clearbutton = gr.Button("Clear")