cipherunhsiv commited on
Commit
6a1b71d
·
verified ·
1 Parent(s): e89fd2b

Upload 2 files

Browse files
Files changed (2) hide show
  1. gradio-version.py +73 -0
  2. requirements.txt +16 -0
gradio-version.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import httpx
3
+ from dotenv import load_dotenv
4
+ import gradio as gr
5
+ from phi.agent import Agent
6
+ from phi.model.groq import Groq
7
+ from phi.storage.agent.postgres import PgAgentStorage
8
+ from phi.knowledge.pdf import PDFUrlKnowledgeBase
9
+ from phi.vectordb.pgvector import PgVector, SearchType
10
+ from phi.embedder.google import GeminiEmbedder
11
+
12
+ # Load environment variables
13
+ load_dotenv()
14
+ os.environ["GROQ_API_KEY"] = os.getenv("GROQ_API_KEY")
15
+
16
+ # HTTP client
17
+ client = httpx.Client(timeout=httpx.Timeout(60.0))
18
+
19
+ # Database connection
20
+ db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai?connect_timeout=60"
21
+
22
+ # Gradio processing function
23
+ def summarize_pdf(pdf_url):
24
+ try:
25
+ # Set up the knowledge base
26
+ knowledge_base = PDFUrlKnowledgeBase(
27
+ urls=[pdf_url],
28
+ vector_db=PgVector(
29
+ table_name="recipies1",
30
+ db_url=db_url,
31
+ embedder=GeminiEmbedder(dimensions=768),
32
+ search_type=SearchType.hybrid,
33
+ )
34
+ )
35
+ # Load and upsert the knowledge base
36
+ knowledge_base.load(recreate=True, upsert=True)
37
+
38
+ # Set up storage and agent
39
+ storage = PgAgentStorage(table_name="pdf-assistant1", db_url=db_url)
40
+ agent = Agent(
41
+ model=Groq(id="llama-3.3-70b-versatile"),
42
+ knowledge=knowledge_base,
43
+ storage=storage,
44
+ )
45
+
46
+ # Generate summary
47
+ response = agent.run("Summarize the document within 5000 tokens!")
48
+ return response.content
49
+ except Exception as e:
50
+ return f"An error occurred: {e}"
51
+
52
+ # Gradio interface
53
+ iface = gr.Interface(
54
+ fn=summarize_pdf,
55
+ inputs=gr.Textbox(
56
+ label="PDF URL",
57
+ placeholder="Enter the URL of a PDF document...",
58
+ lines=1
59
+ ),
60
+ outputs=gr.Textbox(
61
+ label="Output Summary",
62
+ placeholder="The summary will appear here...",
63
+ lines=15
64
+ ),
65
+ examples=[
66
+ ["https://www.joghat.org/uploads/2024-vol-7-issue-1-full-text-405.pdf"]
67
+ ],
68
+ description="Enter a PDF URL to generate a concise summary of the document.",
69
+ title="PDF Summarizer"
70
+ )
71
+
72
+ # Launch the interface
73
+ iface.launch(share=True, debug=True)
requirements.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ phidata
2
+ python-dotenv
3
+ yfinance
4
+ packaging
5
+ duckduckgo-search
6
+ fastapi
7
+ uvicorn
8
+ groq
9
+ openai
10
+ sqlalchemy
11
+ pgvector
12
+ psycopg[binary]
13
+ pypdf
14
+ mistralai
15
+ huggingface_hub
16
+ gradio