PhoenixBomb commited on
Commit
0c0119b
·
verified ·
1 Parent(s): ae2d5ac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import langchain
2
+ import streamlit as st
3
+ from duckduckgo import search
4
+ from bs4 import BeautifulSoup
5
+ import pyttsx3
6
+ import speech_recognition as sr
7
+
8
+ # Set up LangChain
9
+ llm = langchain.llms.OpenAI()
10
+ template = """Answer the following questions as best you can, but speaking as a pirate might speak.
11
+ You have access to the following tools: {tools}
12
+ Use the following format:
13
+ Question: the input question you must answer
14
+ Thought: you should always think about what to do
15
+ Action: the action you will take"""
16
+
17
+ # Set up Groq API credentials
18
+ groq_api_key = "YOUR_GROQ_API_KEY_HERE"
19
+
20
+ # Set up text-to-speech engine
21
+ engine = pyttsx3.init()
22
+
23
+ # Set up speech-to-text recognizer
24
+ recognizer = sr.Recognizer()
25
+
26
+ def get_user_input():
27
+ # Use speech-to-text recognizer to get user input
28
+ with sr.Microphone() as source:
29
+ audio = recognizer.listen(source)
30
+ try:
31
+ user_input = recognizer.recognize_google(audio, language="en-US")
32
+ return user_input
33
+ except sr.UnknownValueError:
34
+ return "Sorry, I didn't quite catch that."
35
+
36
+ def conduct_web_search(query):
37
+ # Use DuckDuckGo to conduct web search
38
+ results = search(query, num_results=10)
39
+ return results
40
+
41
+ def extract_data_from_web(results):
42
+ # Use BeautifulSoup to extract data from web pages
43
+ data = []
44
+ for result in results:
45
+ url = result["url"]
46
+ soup = BeautifulSoup(url, "html.parser")
47
+ # Extract relevant data from webpage
48
+ title = soup.find("title").text
49
+ data.append({"title": title, "url": url})
50
+ return data
51
+
52
+ def summarize_output(data):
53
+ # Use Groq API to summarize output
54
+ summary = langchain.chains.summarize(data, api_key=groq_api_key)
55
+ return summary
56
+
57
+ def main():
58
+ # Get user input
59
+ user_input = get_user_input()
60
+ st.write(f"User input: {user_input}")
61
+
62
+ # Conduct web search
63
+ results = conduct_web_search(user_input)
64
+ st.write(f"Search results: {results}")
65
+
66
+ # Extract data from web
67
+ data = extract_data_from_web(results)
68
+ st.write(f"Extracted data: {data}")
69
+
70
+ # Summarize output
71
+ summary = summarize_output(data)
72
+ st.write(f"Summarized output: {summary}")
73
+
74
+ # Provide output in voice
75
+ engine.say(summary)
76
+ engine.runAndWait()
77
+
78
+ if __name__ == "__main__":
79
+ main()