File size: 4,078 Bytes
a936419
40ce5ac
085ef0b
40ce5ac
1605c68
ae2ec3d
6c974e5
085ef0b
40ce5ac
0963c3d
085ef0b
cb7bc65
 
6ad3993
cb7bc65
ee8bb54
cb7bc65
 
40ce5ac
cb7bc65
 
ee3485c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
074f881
ee3485c
 
0b36bad
618e915
 
 
 
ee3485c
618e915
9c2407c
eb7082a
 
9a43e1d
ee3485c
 
 
eb7082a
ae2ec3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea74c1e
e6bff66
085ef0b
79b0e5e
85deaff
9a43e1d
 
5399f24
40ce5ac
 
 
085ef0b
 
0b36bad
e5d9b98
085ef0b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import gradio as gr
import requests
import os
import json
import google.generativeai as genai
from bs4 import BeautifulSoup

# Load environment variables
genai.configure(api_key=os.environ["geminiapikey"])
read_key = os.environ.get('HF_TOKEN', None)

custom_css = """
#md {
    height: 400px;  
    font-size: 30px;
    background: #202020;
    padding: 20px;
    color: white;
    border: 1 px solid white;
}
"""

def predict(prompt):
    generation_config = {
      "temperature": 0.4,
      "top_p": 0.95,
      "top_k": 40,
      "max_output_tokens": 8192,
      "response_mime_type": "text/plain",
    }

    model = genai.GenerativeModel(
      model_name="gemini-2.0-flash-exp",
      generation_config=generation_config,
    )

    chat_session = model.start_chat(
      history=[
        {
          "role": "user",
          "parts": [
            "return a json object with the contact details. leave blank if information is not available. here is the json schema:\n\n{\n  \"organization\": \"\",\n  \"address\": \"\",\n  \"phone\": \"\",\n  \"email\": \"\",\n  \"website\": \"\"\n}\n\nyou can find the contact details here: \nImpressum – Aero-Club Bamberg e.V.\nAero-Club Bamberg\nhttps://aeroclub-bamberg.de › impressum\nAero-Club Bamberg e.V.. Zeppelinstraße 18. D-96052 Bamberg. Tel.: 0951 / 45 1 45. Fax: 0951 / 13 22 20. E-Mail: info@aeroclub-bamberg.de.\n",
          ],
        },
        {
          "role": "model",
          "parts": [
            "```json\n{\n  \"organization\": \"Aero-Club Bamberg e.V.\",\n  \"address\": \"Zeppelinstraße 18, D-96052 Bamberg\",\n  \"phone\": \"0951 / 45 1 45\",\n  \"email\": \"info@aeroclub-bamberg.de\",\n  \"website\": \"https://aeroclub-bamberg.de\"\n}\n```\n",
          ],
        },
      ]
    )
      
    response = chat_session.send_message("return a json object with the contact details. leave blank if information is not available. here is the json schema:\n\n{\n  \"organization\": \"\",\n  \"address\": \"\",\n  \"phone\": \"\",\n  \"email\": \"\",\n  \"website\": \"\"\n}\n\nyou can find the contact details here: \n" + prompt)
    return response
    
def get_impressum_text(search_term):
    
    headers = {
        "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"
    }
    vereine = []
    #search_results = google_search(search_term)
    url = f"https://www.google.com/search?q=mpressum {search_term}"
    response = requests.get(url, headers=headers)
    soup = BeautifulSoup(response.content, 'html.parser')
    impressum_div = soup.find('body')
    json_data = predict(impressum_div.text)
    vereine.append(json_data)
    return vereine

def websearch(prompt):
    
    url = f"https://www.google.com/search?q={prompt}"
    headers = {
        "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"
    }
    
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status() # Wirft eine Exception für Fehlercodes
    except requests.exceptions.RequestException as e:
       print(f"Fehler beim Abrufen der Google-Seite: {e}")
       return None

    soup = BeautifulSoup(response.content, 'html.parser')
    
    first_div = soup.find('div', class_='MjjYud')
    
    if first_div:
        return first_div.text.strip()
    else:
        print("Kein div mit der Klasse 'MjjYud' gefunden.")
        return None



# Create the Gradio interface
with gr.Blocks(css=custom_css) as demo:
    with gr.Row():
        #details_output = gr.Markdown(label="answer", elem_id="md")        
        details_output = gr.Textbox(label="Ausgabe", value = f"\n\n\n\n")  
    with gr.Row():
        ort_input = gr.Textbox(label="prompt", placeholder="ask anything...")      
    with gr.Row():         
        button = gr.Button("Senden")    

    # Connect the button to the function
    button.click(fn=get_impressum_text, inputs=ort_input, outputs=details_output)   

# Launch the Gradio application
demo.launch()