Stepheni12's picture
testing colors 3
aef8599
import chromadb
import os
import gradio as gr
client = chromadb.PersistentClient(path="./db1")
collection = client.get_or_create_collection("test")
def query_episodes(query, n_results):
output = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Podcast Episodes</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap">
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #ffffff;
margin: 0;
padding: 20px; /* Add padding to the body to separate it from the podcast container */
box-sizing: border-box;
}
.podcast-container {
max-height: 500px; /* Set a fixed height for the podcast container */
overflow-y: auto; /* Enable scrolling if content exceeds the container height */
width: 600px; /* Set a fixed width for the podcast container */
margin: auto; /* Center the podcast container horizontally */
}
.episode-container {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border-radius: 8px;
overflow: hidden;
margin-bottom: 20px;
color: #ffffff;
}
.episode-title {
background-color: #3498db;
padding: 15px;
font-size: 22px;
font-weight: bold;
text-align: center;
}
.episode-content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
overflow-y: auto;
}
.paragraph-number {
font-size: 18px;
margin-bottom: 8px;
}
.paragraph-text {
font-size: 16px;
line-height: 1.4;
text-align: center;
}
/* Hide the scrollbar */
.podcast-container::-webkit-scrollbar {
width: 0 !important;
display: none;
}
</style>
</head>
<body>
<div class="podcast-container">
"""
q = collection.query(
query_texts=[query],
n_results=n_results)
for idx in range(n_results):
output += """
<div class="episode-container">
<div class="episode-title">Episode: {}</div>
<div class="episode-content">
<div class="paragraph-number">Paragraph: {}</div>
<div class="paragraph-text">
{}
</div>
</div>
</div>
""".format(q["metadatas"][0][idx]["title"], q["metadatas"][0][idx]["paragraph"], q["documents"][0][idx])
output += """
</div>
</body>
</html>
"""
return output
if __name__ == "__main__":
description = "With a podcast like the Huberman Lab podcast it can sometimes be overwhelming trying to find the exact content you are looking for. This tool is meant to start you in the right direction depending on the topic you are searching for."
article = """For any input or suggestions hit me up on [twitter](https://twitter.com/intent/user?screen_name=_isteph_)!"""
examples = [
["Stretching routine", 3],
["Cold exposure", 5],
["Handling ADHD", 2],
["Eating healthy", 8]
]
interface = gr.Interface(
fn=query_episodes,
inputs=[gr.Textbox(label="Search Query",show_label=True), gr.Slider(value=3, minimum=1, maximum=10, step=1, label="Number of Results")],
outputs=[gr.HTML(label="Consolidated Query Results", show_label=True)],
title="Huberman Lab Podcast Topic Search",
examples=examples,
description=description,
article=article
)
interface.launch()