mgokg commited on
Commit
cb954b3
·
verified ·
1 Parent(s): c58f0e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -29,6 +29,22 @@ google_api_key = os.getenv('google_search')
29
  # Initialize the Groq client
30
  #client = Groq(api_key=api_key)
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  def perform_search(prompt):
33
  if prompt.strip() == '':
34
  return '' # Return empty string for empty search
@@ -92,7 +108,7 @@ with gr.Blocks(css=custom_css) as demo:
92
  button = gr.Button("Senden")
93
 
94
  # Connect the button to the function
95
- button.click(fn=perform_search, inputs=ort_input, outputs=details_output)
96
 
97
  # Launch the Gradio application
98
  demo.launch()
 
29
  # Initialize the Groq client
30
  #client = Groq(api_key=api_key)
31
 
32
+ #very simple (and extremly fast) websearch
33
+ def websearch(prompt):
34
+ headers = {
35
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
36
+ }
37
+ # URL der Google Custom Search API
38
+ url = f"https://www.googleapis.com/customsearch/v1?key={google_api_key}&cx={cx}&q={prompt}"
39
+ response = requests.get(url, headers=headers)
40
+ soup = BeautifulSoup(response.content, 'html.parser')
41
+ response_text = soup.find('body')
42
+ prompt = f"{search_term}\n use this result from a google search to answer the question \n {response_text.text}"
43
+ #result = predict(prompt)
44
+ return response_text.text
45
+
46
+
47
+
48
  def perform_search(prompt):
49
  if prompt.strip() == '':
50
  return '' # Return empty string for empty search
 
108
  button = gr.Button("Senden")
109
 
110
  # Connect the button to the function
111
+ button.click(fn=websearch, inputs=ort_input, outputs=details_output)
112
 
113
  # Launch the Gradio application
114
  demo.launch()