Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,45 @@
|
|
1 |
import streamlit as st
|
2 |
from teapotai import TeapotAI, TeapotAISettings
|
3 |
import hashlib
|
|
|
|
|
4 |
|
5 |
-
default_documents =
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
"The Sahara Desert is the largest hot desert in the world, located in North Africa. Spanning over 9 million square kilometers, it is known for its vast sand dunes, extreme temperatures, and minimal rainfall. Despite the harsh conditions, the Sahara is home to a variety of life, including desert plants, animals, and nomadic human populations. The desert’s landscape is a stunning mix of rocky plateaus, vast sand dunes, and occasional oases.",
|
19 |
-
|
20 |
-
"The Nile River is the longest river in the world, flowing through northeastern Africa. It stretches over 6,600 kilometers and has been a vital resource for the civilizations of Egypt and Sudan for thousands of years. The river provides fertile land for agriculture in an otherwise arid region and has played a significant role in the development of these ancient cultures. Today, it remains an essential lifeline for the millions of people who live along its banks.",
|
21 |
-
|
22 |
-
"The Empire State Building is an iconic skyscraper in New York City that was completed in 1931 and stands at 1454 feet tall. Designed in the Art Deco style by architect William F. Lamb, it was the tallest building in the world until 1970. The Empire State Building features observation decks that offer stunning views of the city and remains an enduring symbol of New York’s skyline. It continues to attract millions of visitors from around the world each year.",
|
23 |
-
|
24 |
-
"The Pyramids of Giza are a group of ancient Egyptian structures located on the outskirts of Cairo. The Great Pyramid, built for Pharaoh Khufu, is the largest and one of the Seven Wonders of the Ancient World. These massive stone structures were constructed as tombs for the Pharaohs and their queens. The pyramids, along with the nearby Sphinx, are one of Egypt’s most famous tourist attractions, drawing visitors from across the globe.",
|
25 |
-
|
26 |
-
"The Taj Mahal is a stunning white marble mausoleum located in Agra, India. Built by Emperor Shah Jahan in memory of his wife Mumtaz Mahal, it is considered one of the finest examples of Mughal architecture. The Taj Mahal is known for its intricate designs, including detailed carvings and inlaid gemstones. It is a UNESCO World Heritage site and attracts millions of visitors annually for its beauty and historical significance.",
|
27 |
-
|
28 |
-
"The Sydney Opera House is a world-renowned performing arts center located in Sydney, Australia. Completed in 1973, the building is famous for its unique sail-like design and stunning location on Sydney Harbour. It is one of the most recognizable architectural landmarks in the world and hosts a wide range of performances, from opera and ballet to theater and concerts. The Opera House is a symbol of Australia’s vibrant cultural scene.",
|
29 |
-
|
30 |
-
"The Statue of Liberty is a colossal sculpture located on Liberty Island in New York Harbor. A gift from France to the United States in 1886, the statue symbolizes freedom and democracy. Standing at 305 feet tall from base to torch, it was the tallest structure in New York City when it was erected. Today, it remains one of the most famous landmarks in the world and is a symbol of hope and opportunity for millions of immigrants.",
|
31 |
-
|
32 |
-
"Machu Picchu is an ancient Inca citadel located high in the Andes Mountains of Peru. Built in the 15th century, it was a royal estate and a religious site for the Inca civilization. The site is renowned for its advanced dry-stone construction and stunning location, perched atop a mountain ridge with sweeping views of the surrounding landscape. Machu Picchu is one of the most important archaeological sites in South America and a UNESCO World Heritage site.",
|
33 |
-
|
34 |
-
"Stonehenge is a prehistoric monument located in Wiltshire, England. Believed to have been constructed between 3000 and 2000 BCE, Stonehenge consists of a ring of standing stones, some weighing up to 25 tons. Its purpose remains a mystery, though it is thought to have been used for religious or ceremonial purposes. Stonehenge attracts thousands of visitors each year who marvel at its ancient mystery and connection to early human history.",
|
35 |
-
|
36 |
-
"The Acropolis of Athens is an ancient citadel located on a rocky outcrop above the city of Athens, Greece. It is home to several ancient structures, including the Parthenon, a temple dedicated to the goddess Athena. The Acropolis is considered a symbol of classical Greek civilization and is one of the most important archaeological sites in the world. It attracts millions of visitors annually who come to admire its historical and architectural significance.",
|
37 |
-
|
38 |
-
"The Christ the Redeemer statue is a giant statue of Jesus Christ located in Rio de Janeiro, Brazil. Standing 98 feet tall and with outstretched arms, it overlooks the city from the peak of Corcovado Mountain. Completed in 1931, the statue is an iconic symbol of Christianity and Brazilian culture. It is one of the New Seven Wonders of the World and offers stunning views of Rio and its surrounding beaches.",
|
39 |
|
40 |
-
|
41 |
|
42 |
-
|
43 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
# Function to handle the chat with TeapotAI
|
46 |
def handle_chat(user_input, teapot_ai):
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
response = teapot_ai.chat([
|
48 |
{
|
49 |
"role": "system",
|
50 |
-
"content": "You are an
|
51 |
},
|
52 |
{
|
53 |
"role": "user",
|
|
|
1 |
import streamlit as st
|
2 |
from teapotai import TeapotAI, TeapotAISettings
|
3 |
import hashlib
|
4 |
+
import os
|
5 |
+
import requests
|
6 |
|
7 |
+
default_documents = []
|
8 |
+
|
9 |
+
API_KEY = os.environ.get("MY_SECRET_KEY")
|
10 |
+
|
11 |
+
def brave_search(query, count=3):
|
12 |
+
url = "https://api.search.brave.com/res/v1/web/search"
|
13 |
+
headers = {"Accept": "application/json", "X-Subscription-Token": API_KEY}
|
14 |
+
params = {
|
15 |
+
"q": query,
|
16 |
+
"count": count,
|
17 |
+
"extra_snippets": True
|
18 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
response = requests.get(url, headers=headers, params=params)
|
21 |
|
22 |
+
if response.status_code == 200:
|
23 |
+
results = response.json().get("web", {}).get("results", [])
|
24 |
+
print(results)
|
25 |
+
return [(res["title"], res["description"], res["url"]) for res in results]
|
26 |
+
else:
|
27 |
+
print(f"Error: {response.status_code}, {response.text}")
|
28 |
+
return []
|
29 |
+
|
30 |
|
31 |
# Function to handle the chat with TeapotAI
|
32 |
def handle_chat(user_input, teapot_ai):
|
33 |
+
results = brave_search(user_input)
|
34 |
+
|
35 |
+
for i, (title, description, url) in enumerate(results, 1):
|
36 |
+
print(f"{i}. {title}\n {description.replace('<strong>','').replace('</strong>','')}\n {url}\n")
|
37 |
+
st.write(f"{i}. {title}\n {description.replace('<strong>','').replace('</strong>','')}\n {url}\n")
|
38 |
+
|
39 |
response = teapot_ai.chat([
|
40 |
{
|
41 |
"role": "system",
|
42 |
+
"content": "You are Teapot, an open-source AI assistant optimized for running efficiently on low-end devices. You provide short, accurate responses without hallucinating and excel at extracting information and summarizing text."
|
43 |
},
|
44 |
{
|
45 |
"role": "user",
|