Spaces:
Sleeping
Sleeping
File size: 10,173 Bytes
f7d4608 |
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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# from pydantic import BaseModel
# from openai import OpenAI
# from typing import List, Dict, Optional, Union
# client = OpenAI()
# class GHGParameter(BaseModel):
# parameter: str
# data_type: str
# synonyms: Optional[List[str]] = None
# uom: Optional[str] = None
# description: Optional[str] = None
# value: Union[int, str, None]
# class GHGCategory(BaseModel):
# category: str
# parameters: List[GHGParameter]
# SCHEMA = """{
# "Gas (GHG)": {
# "Total GHG Emissions": {
# "data_type": "Numeric",
# "synonyms": ["Carbon Footprint"],
# "uom": "Metric Tons CO₂e",
# "description": "Total greenhouse gases emitted by the organization.",
# "value": null
# }"""
# PROMPT = (f"""You are a PDF parsing agent.
# Fetch the following data from pdf : {SCHEMA}"""
# )
# def extract_emissions_data_as_json(api, model, file_input):
# if api.lower() == "openai":
# file = client.files.create(
# file=("uploaded.pdf", file_input),
# purpose="assistants"
# )
# completion = client.beta.chat.completions.parse(
# model="gpt-4o-2024-08-06",
# messages=[
# {
# "role": "user",
# "content": [
# {
# "type": "file",
# "file": {
# "file_id": file.id,
# }
# },
# {
# "type": "text",
# "text":PROMPT,
# },
# ]
# }
# ],
# response_format=GHGCategory,
# )
# research_paper = completion.choices[0].message.parsed
# return research_paper
# from pydantic import BaseModel
# from openai import OpenAI
# client = OpenAI()
# class CalendarEvent(BaseModel):
# name: str
# date: str
# participants: list[str]
# def extract_emissions_data_as_json(api, model, file_input):
# if api.lower() == "openai":
# file = client.files.create(
# file=("uploaded.pdf", file_input),
# purpose="assistants"
# )
# completion = client.beta.chat.completions.parse(
# model="gpt-4o-2024-08-06",
# messages=[
# {
# "role": "user",
# "content": [
# {
# "type": "file",
# "file": {
# "file_id": file.id,
# }
# },
# {
# "type": "text",
# "text":PROMPT,
# },
# ]
# }
# ],
# response_format=GHGCategory,
# )
# event = completion.choices[0].message.parsed
# response = client.chat.completions.create(
# model="gpt-4o-2024-08-06",
# messages=[
# {"role": "system", "content": "You are a helpful math tutor. Guide the user through the solution step by step."},
# {"role": "user", "content": "how can I solve 8x + 7 = -23"}
# ],
# response_format={
# "type": "json_schema",
# "json_schema": {
# "name": "GHGCategory",
# "schema": {
# "type": "object",
# "properties": {
# "steps": {
# "type": "array",
# "items": {
# "type": "object",
# "properties": {
# "explanation": {"type": "string"},
# "output": {"type": "string"}
# },
# "required": ["explanation", "output"],
# "additionalProperties": False
# }
# },
# "final_answer": {"type": "string"}
# },
# "required": ["steps", "final_answer"],
# "additionalProperties": False
# },
# "strict": True
# }
# }
# )
# print(response.choices[0].message.content)
# response = await async_client.responses.create(
# model="gpt-4o",
# input=[
# {
# "role": "user",
# "content": [
# {
# "type": "input_file",
# "file_id": uploaded_file.id,
# },
# {
# "type": "input_text",
# "text": """
# You are an intelligent PDF data extractor designed to extract structured information from Brand Books. A Brand Book contains guidelines and details about a brand's identity, including its logo, colors, typography, messaging, and more.
# Ensure the extracted data follows this schema strictly.
# Return the extracted brand information in JSON format with no explaination.
# For brand_logo and favicon, always provide a direct URL to the image instead of just the image name or a placeholder. If no valid URLs are found, return an empty array. """
# }
# ]
# }
# ],
# text={
# "format": {
# "type": "json_schema",
# "name": "BrandBook",
# "strict": True,
# "schema": {
# "type": "object",
# "properties": {
# "brand_url": {
# "type": "string",
# "description": "The URL associated with the brand."
# },
# "brand_name": {
# "type": "string",
# "description": "The name of the brand."
# },
# "brand_category": {
# "type": "array",
# "description": "A list of categories that the brand belongs to.",
# "items": {
# "type": "string"
# }
# },
# "brand_description": {
# "type": "string",
# "description": "A brief description of the brand."
# },
# "brand_colors": {
# "type": "array",
# "description": "A list of colors associated with the brand.",
# "items": {
# "type": "string"
# }
# },
# "brand_fonts": {
# "type": "array",
# "description": "A list of fonts used by the brand.",
# "items": {
# "type": "string"
# }
# },
# "brand_logo": {
# "type": "array",
# "description": "A list of logo urls associated with the brand.",
# "items": {
# "type": "string"
# }
# },
# "target_audience": {
# "type": "string",
# "description": "The target audience for the brand."
# },
# "competitors": {
# "type": "string",
# "description": "The competitors of the brand."
# },
# "aspirational_brands": {
# "type": "string",
# "description": "Brands that the brand aspires to be like."
# },
# "favicon": {
# "type": "array",
# "description": "A list of favicon URLs associated with the brand.",
# "items": {
# "type": "string"
# }
# }
# },
# "required": [
# "brand_url",
# "brand_name",
# "brand_category",
# "brand_description",
# "brand_colors",
# "brand_fonts",
# "brand_logo",
# "target_audience",
# "competitors",
# "aspirational_brands",
# "favicon"
# ],
# "additionalProperties": False
# }
# }
# }
# ) |