File size: 2,226 Bytes
c3b7bd1
 
 
f542379
df9dd4d
17614fa
 
 
1aa8a78
 
89234f1
17614fa
 
 
 
c3b7bd1
1aa8a78
 
 
 
 
 
 
 
7a04bdb
1aa8a78
 
0b89a53
1aa8a78
 
 
 
 
 
89c900b
247bec9
17614fa
a8b7167
6c496a2
d5321f0
2f7e2da
a8b7167
dc69473
0eb5ebd
38d289f
a8b7167
54b7833
1aa8a78
79ac338
2f7e2da
3b7d2d0
2f7e2da
 
 
beb38d8
c3b7bd1
0d04d2e
3f8a236
4e82f2d
5879af1
 
c3b7bd1
 
2f7e2da
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
import gradio as gr
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By
from gradio_client import Client
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
import groq
import os
import time

options = webdriver.ChromeOptions()
options.add_argument('--headless')
wd = webdriver.Chrome(options=options)

#get your api-key @groq.com. its free!
api_key = os.getenv('groq')
client = groq.Client(api_key=api_key)

# Use Llama 3 70B powered by Groq for answering
def update(prompt, ort):   
    try:        
        completion = client.chat.completions.create(
            model="llama3-70b-8192",
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": f"gefragt sind die nächsten 3 zugverbindungen von bad kissingen nach {ort} du findest die antwort im kontext. liefer als antwort ein 2 spaltige tabelle. linke spalte: abfahrtszeit, fahrtdauer, ankunftszeit.rechte spalte: abfahrtsort,leer,zielort. formatiere die tabelle in markdown\n kontext: \n {prompt} \n antworte immer auf deutsch!"}
            ],
        )       
        return completion.choices[0].message.content
    except Exception as e:
        return f"Error in response generation: {str(e)}"

def selenium(message):

    try:       
        url = f"https://www.google.com/search?q=zugverbindung+bad+kissingen+{message}"
        #url = 'https://www.spiegel.de'
        #<ol class="AmbQnf">
        wd.get(url)
        wd.implicitly_wait(3)
        element = wd.find_element(By.TAG_NAME, "body")
        #texts = [element.text for element in elements]
        wd.quit()
        time.sleep(1)
        results = update(element.text, message)
        return results

    except WebDriverException as e:
        return "fehler"
    finally:
        if wd:
            wd.quit()
                  
iface = gr.Interface(
    fn=selenium,
    inputs="text",
    outputs=gr.Markdown(),
    title="perplexity.ai",
    description="get answer from perplexity"
)

iface.launch()