import langchain import streamlit as st from duckduckgo import search from bs4 import BeautifulSoup import pyttsx3 import speech_recognition as sr # Set up LangChain llm = langchain.llms.OpenAI() template = """Answer the following questions as best you can, but speaking as a pirate might speak. You have access to the following tools: {tools} Use the following format: Question: the input question you must answer Thought: you should always think about what to do Action: the action you will take""" # Set up Groq API credentials groq_api_key = "YOUR_GROQ_API_KEY_HERE" # Set up text-to-speech engine engine = pyttsx3.init() # Set up speech-to-text recognizer recognizer = sr.Recognizer() def get_user_input(): # Use speech-to-text recognizer to get user input with sr.Microphone() as source: audio = recognizer.listen(source) try: user_input = recognizer.recognize_google(audio, language="en-US") return user_input except sr.UnknownValueError: return "Sorry, I didn't quite catch that." def conduct_web_search(query): # Use DuckDuckGo to conduct web search results = search(query, num_results=10) return results def extract_data_from_web(results): # Use BeautifulSoup to extract data from web pages data = [] for result in results: url = result["url"] soup = BeautifulSoup(url, "html.parser") # Extract relevant data from webpage title = soup.find("title").text data.append({"title": title, "url": url}) return data def summarize_output(data): # Use Groq API to summarize output summary = langchain.chains.summarize(data, api_key=groq_api_key) return summary def main(): # Get user input user_input = get_user_input() st.write(f"User input: {user_input}") # Conduct web search results = conduct_web_search(user_input) st.write(f"Search results: {results}") # Extract data from web data = extract_data_from_web(results) st.write(f"Extracted data: {data}") # Summarize output summary = summarize_output(data) st.write(f"Summarized output: {summary}") # Provide output in voice engine.say(summary) engine.runAndWait() if __name__ == "__main__": main()