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="Mixtral-8x7b-32768", 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' #
    wd.get(url) wd.implicitly_wait(3) element = wd.find_element(By.TAG_NAME, "body") #texts = [element.text for element in elements] 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()