import json import os import requests def get_transcript_for_url(url: str) -> dict: """ This function fetches the transcript data for a signed URL. If the URL results in a direct download, it processes the downloaded content. :param url: Signed URL for the JSON file :return: Parsed JSON data as a dictionary """ headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" } try: response = requests.get(url, headers=headers) response.raise_for_status() if "application/json" in response.headers.get("Content-Type", ""): return response.json() # Parse and return JSON directly # If not JSON, assume it's a file download (e.g., content-disposition header) content_disposition = response.headers.get("Content-Disposition", "") if "attachment" in content_disposition: # Process the content as JSON return json.loads(response.content) return json.loads(response.content) except requests.exceptions.HTTPError as http_err: print(f"HTTP error occurred: {http_err}") except requests.exceptions.RequestException as req_err: print(f"Request error occurred: {req_err}") except json.JSONDecodeError as json_err: print(f"JSON decoding error: {json_err}") return {} def setup_openai_key() -> None: """Set up OpenAI API key from file.""" try: with open("api.key", "r") as f: os.environ["OPENAI_API_KEY"] = f.read().strip() except FileNotFoundError: print("Using ENV variable") openai_tools = [ { "type": "function", "function": { "name": "correct_speaker_name_with_url", "description": "If a User provides a link to Agenda file, call the correct_speaker_name_with_url function to correct the speaker names based on the url, i.e if a user says 'Here is the Luma link for the event' and provides a link to the event, the function will correct the speaker names based on the event.", "parameters": { "type": "object", "properties": { "url": {"type": "string", "description": "The url to the agenda."} }, "required": ["url"], "additionalProperties": False, }, }, }, { "type": "function", "function": { "name": "correct_call_type", "description": "If the user tells you the correct call type, you have to apologize and call this function with correct call type.", "parameters": { "type": "object", "properties": { "call_type": { "type": "string", "description": "The correct call type. If street interview, call type is 'si'.", } }, "required": ["call_type"], "additionalProperties": False, }, }, }, { "type": "function", "function": { "name": "get_image", "description": "If the user asks you to show crops, you need to call this function", "parameters": { "type": "object", "properties": {}, "required": [], "additionalProperties": False, }, }, }, ] css = """ .gradio-container { padding-top: 0px !important; padding-left: 0px !important; padding-right: 0px !important; padding: 0px !important; margin: 0px !important; } #component-0 { gap: 0px !important; } .icon-button-wrapper button[title="Clear"] { display: none !important; } .image-preview .icon-button-wrapper { display: block !important; } .image-preview .icon-button-wrapper button[title="Clear"] { display: block !important; } .download-link { display: none !important; } footer { display: none !important; } #chatbot_box{ flex-grow: 1 !important; border-width: 0px !important; } #link-frame { position: absolute !important; width: 1px !important; height: 1px !important; right: -100px !important; bottom: -100px !important; display: none !important; } .html-container { display: none !important; } a { text-decoration: none !important; } #topic { color: #999 !important; } .bubble-wrap { padding-top: 0px !important; } .message-content { border: 0px !important; margin: 5px !important; } .message-row { border-style: none !important; margin: 0px !important; width: 100% !important; max-width: 100% !important; } .flex-wrap { border-style: none !important; } .panel-full-width { border-style: none !important; border-width: 0px !important; } ol { list-style-position: outside; margin-left: 20px; } body.waiting * { cursor: progress; } """ head = f""" """