Spaces:
Sleeping
Sleeping
File size: 3,881 Bytes
c3e305d 9cc1da2 c3e305d f13d295 aef8599 f13d295 33bfd7e f13d295 3856123 f13d295 c3e305d f13d295 c3e305d f13d295 6054f64 f13d295 c3e305d f13d295 c3e305d f13d295 c3e305d 9cc1da2 |
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
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()
|