File size: 2,276 Bytes
0c0119b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()