Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
import json
|
3 |
import asyncio
|
|
|
4 |
import gradio as gr
|
5 |
import httpx
|
6 |
|
@@ -15,7 +16,12 @@ perplexity_client = PerplexityClient(
|
|
15 |
api_key=os.environ["PERPLEXITY_AUTH_TOKEN"]
|
16 |
)
|
17 |
|
18 |
-
async def query_api(query: str) -> tuple:
|
|
|
|
|
|
|
|
|
|
|
19 |
try:
|
20 |
# Fetch response from Perplexity
|
21 |
response = await perplexity_client.generate_response(query)
|
@@ -62,7 +68,23 @@ with gr.Blocks(css=".gradio-container { background-color: #f5f5f5; padding: 20px
|
|
62 |
label="Enter your query",
|
63 |
placeholder="Type your search query here...",
|
64 |
lines=2,
|
65 |
-
max_lines=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
value="",
|
67 |
elem_id="query-input"
|
68 |
)
|
@@ -91,7 +113,7 @@ with gr.Blocks(css=".gradio-container { background-color: #f5f5f5; padding: 20px
|
|
91 |
)
|
92 |
|
93 |
# Set up event listener
|
94 |
-
submit_button.click(query_api, inputs=query, outputs=[output_content, output_citations])
|
95 |
|
96 |
gr.Markdown("Powered by FastAPI and Gradio")
|
97 |
|
|
|
1 |
import os
|
2 |
import json
|
3 |
import asyncio
|
4 |
+
from datetime import datetime
|
5 |
import gradio as gr
|
6 |
import httpx
|
7 |
|
|
|
16 |
api_key=os.environ["PERPLEXITY_AUTH_TOKEN"]
|
17 |
)
|
18 |
|
19 |
+
async def query_api(query: str, website: str, after_date: str) -> tuple:
|
20 |
+
if website:
|
21 |
+
query = query + f" site:{website}"
|
22 |
+
if after_date:
|
23 |
+
query = query + f" after:{after_date}"
|
24 |
+
print("query: ", query)
|
25 |
try:
|
26 |
# Fetch response from Perplexity
|
27 |
response = await perplexity_client.generate_response(query)
|
|
|
68 |
label="Enter your query",
|
69 |
placeholder="Type your search query here...",
|
70 |
lines=2,
|
71 |
+
max_lines=20,
|
72 |
+
value="",
|
73 |
+
elem_id="query-input"
|
74 |
+
)
|
75 |
+
website = gr.Textbox(
|
76 |
+
label="Single website search",
|
77 |
+
placeholder="website url",
|
78 |
+
lines=1,
|
79 |
+
max_lines=20,
|
80 |
+
value="",
|
81 |
+
elem_id="query-input"
|
82 |
+
)
|
83 |
+
after_date = gr.Textbox(
|
84 |
+
label="After date",
|
85 |
+
placeholder="date format: DD-MM-YYYY",
|
86 |
+
lines=1,
|
87 |
+
max_lines=2,
|
88 |
value="",
|
89 |
elem_id="query-input"
|
90 |
)
|
|
|
113 |
)
|
114 |
|
115 |
# Set up event listener
|
116 |
+
submit_button.click(query_api, inputs=[query, website, after_date], outputs=[output_content, output_citations])
|
117 |
|
118 |
gr.Markdown("Powered by FastAPI and Gradio")
|
119 |
|