freddyaboulton HF staff commited on
Commit
36e2c69
·
1 Parent(s): 9fda3c0
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -8,6 +8,7 @@ from typing import AsyncGenerator
8
 
9
  import asyncpg
10
  import gradio as gr
 
11
  import numpy as np
12
  import pydantic_core
13
  from gradio_webrtc import (
@@ -24,6 +25,11 @@ from pydantic_ai import RunContext
24
  from pydantic_ai.agent import Agent
25
  from pydantic_ai.messages import ModelStructuredResponse, ModelTextResponse, ToolReturn
26
 
 
 
 
 
 
27
  DOCS = json.load(open("gradio_docs.json"))
28
 
29
  groq_client = Groq()
@@ -38,7 +44,7 @@ class Deps:
38
 
39
  SYSTEM_PROMPT = (
40
  "You are an assistant designed to help users answer questions about Gradio. "
41
- "You have a retrival tool that can provide relevant documentation sections based on the user query. "
42
  "Be curteous and helpful to the user but feel free to refuse answering questions that are not about Gradio. "
43
  )
44
 
@@ -60,7 +66,7 @@ async def database_connect(
60
  create_db: bool = False,
61
  ) -> AsyncGenerator[asyncpg.Pool, None]:
62
  server_dsn, database = (
63
- os.getenv("DATABASE_URL"),
64
  "gradio_ai_rag",
65
  )
66
  if create_db:
@@ -171,7 +177,7 @@ async def stream_from_agent(
171
  with gr.Blocks() as demo:
172
  placeholder = """
173
  <div style="display: flex; justify-content: center; align-items: center; gap: 1rem; padding: 1rem; width: 100%">
174
- <img src="/gradio_api/file=logo.svg" style="max-width: 200px; height: auto">
175
  <div>
176
  <h1 style="margin: 0 0 1rem 0">Chat with Gradio Docs 🗣️</h1>
177
  <h3 style="margin: 0 0 0.5rem 0">
@@ -188,7 +194,7 @@ with gr.Blocks() as demo:
188
  label="Gradio Docs Bot",
189
  type="messages",
190
  placeholder=placeholder,
191
- avatar_images=(None, "logo.svg"),
192
  )
193
  audio = WebRTC(
194
  label="Talk with the Agent",
@@ -210,4 +216,4 @@ with gr.Blocks() as demo:
210
 
211
 
212
  if __name__ == "__main__":
213
- demo.launch(allowed_paths=["logo.svg"])
 
8
 
9
  import asyncpg
10
  import gradio as gr
11
+ from gradio.utils import get_space
12
  import numpy as np
13
  import pydantic_core
14
  from gradio_webrtc import (
 
25
  from pydantic_ai.agent import Agent
26
  from pydantic_ai.messages import ModelStructuredResponse, ModelTextResponse, ToolReturn
27
 
28
+ if not get_space():
29
+ from dotenv import load_dotenv
30
+
31
+ load_dotenv()
32
+
33
  DOCS = json.load(open("gradio_docs.json"))
34
 
35
  groq_client = Groq()
 
44
 
45
  SYSTEM_PROMPT = (
46
  "You are an assistant designed to help users answer questions about Gradio. "
47
+ "You have a retrieve tool that can provide relevant documentation sections based on the user query. "
48
  "Be curteous and helpful to the user but feel free to refuse answering questions that are not about Gradio. "
49
  )
50
 
 
66
  create_db: bool = False,
67
  ) -> AsyncGenerator[asyncpg.Pool, None]:
68
  server_dsn, database = (
69
+ os.getenv("DB_URL"),
70
  "gradio_ai_rag",
71
  )
72
  if create_db:
 
177
  with gr.Blocks() as demo:
178
  placeholder = """
179
  <div style="display: flex; justify-content: center; align-items: center; gap: 1rem; padding: 1rem; width: 100%">
180
+ <img src="/gradio_api/file=gradio_logo.png" style="max-width: 200px; height: auto">
181
  <div>
182
  <h1 style="margin: 0 0 1rem 0">Chat with Gradio Docs 🗣️</h1>
183
  <h3 style="margin: 0 0 0.5rem 0">
 
194
  label="Gradio Docs Bot",
195
  type="messages",
196
  placeholder=placeholder,
197
+ avatar_images=(None, "gradio_logo.png"),
198
  )
199
  audio = WebRTC(
200
  label="Talk with the Agent",
 
216
 
217
 
218
  if __name__ == "__main__":
219
+ demo.launch(allowed_paths=["gradio_logo.png"])