|
| 1 | +import os, json |
| 2 | +from dotenv import load_dotenv |
| 3 | +from scrapegraphai.graphs import PDFScraperGraph |
| 4 | + |
| 5 | +load_dotenv() |
| 6 | + |
| 7 | + |
| 8 | +# ************************************************ |
| 9 | +# Define the configuration for the graph |
| 10 | +# ************************************************ |
| 11 | + |
| 12 | +openai_key = os.getenv("OPENAI_APIKEY") |
| 13 | + |
| 14 | +graph_config = { |
| 15 | + "llm": { |
| 16 | + "api_key": openai_key, |
| 17 | + "model": "gpt-3.5-turbo", |
| 18 | + }, |
| 19 | + "verbose": True, |
| 20 | + "headless": False, |
| 21 | +} |
| 22 | + |
| 23 | +source = """ |
| 24 | + The Divine Comedy, Italian La Divina Commedia, original name La commedia, long narrative poem written in Italian |
| 25 | + circa 1308/21 by Dante. It is usually held to be one of the world s great works of literature. |
| 26 | + Divided into three major sections—Inferno, Purgatorio, and Paradiso—the narrative traces the journey of Dante |
| 27 | + from darkness and error to the revelation of the divine light, culminating in the Beatific Vision of God. |
| 28 | + Dante is guided by the Roman poet Virgil, who represents the epitome of human knowledge, from the dark wood |
| 29 | + through the descending circles of the pit of Hell (Inferno). He then climbs the mountain of Purgatory, guided |
| 30 | + by the Roman poet Statius, who represents the fulfilment of human knowledge, and is finally led by his lifelong love, |
| 31 | + the Beatrice of his earlier poetry, through the celestial spheres of Paradise. |
| 32 | +""" |
| 33 | + |
| 34 | +schema = """ |
| 35 | + { |
| 36 | + "type": "object", |
| 37 | + "properties": { |
| 38 | + "summary": { |
| 39 | + "type": "string" |
| 40 | + }, |
| 41 | + "topics": { |
| 42 | + "type": "array", |
| 43 | + "items": { |
| 44 | + "type": "string" |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | +""" |
| 50 | + |
| 51 | +pdf_scraper_graph = PDFScraperGraph( |
| 52 | + prompt="Summarize the text and find the main topics", |
| 53 | + source=source, |
| 54 | + config=graph_config, |
| 55 | + schema=schema, |
| 56 | +) |
| 57 | +result = pdf_scraper_graph.run() |
| 58 | + |
| 59 | +print(json.dumps(result, indent=4)) |
0 commit comments