import os import openai from openai.error import OpenAIError import datetime import gradio as gr import json from jinja2 import Template import requests # Configuration variables airtable_api_key = os.environ.get('AIRTABLE_API_KEY') examples_table_name = 'tblu7sraOEmRgEGkp' #Airtable Base ID base_id = 'appcUK3hUWC7GM2Kb' # Define the style and content for the response field label_text = "NILI Response" color = "#6562F4" background_color = "white" border_radius = "10px" response_label = f'{label_text}' #Name of the prompt temlate record #prompt_name = "NILI_v1" #App name for user login logging app="NILI_Mobile" #Header for the Airtable requests headers = { "Authorization": f"Bearer {airtable_api_key}", "Content-Type": "application/json", "Accept": "application/json", } def get_examples(): ui_examples = [] airtable_endpoint = f'https://api.airtable.com/v0/{base_id}/{examples_table_name}' params = { 'filterByFormula': f'app = "{app}"', 'fields[]': 'nil_question' } # Send your request and parse the response response = requests.get(airtable_endpoint, headers=headers,params=params) data = json.loads(response.text) # Check for errors response.raise_for_status() # Initialize a nested list to store nil_questions nested_nil_questions = [] for record in data['records']: nil_question = record['fields']['nil_question'] ui_examples.append(nil_question) #print(ui_examples) return ui_examples #Gradio UI CIMStheme = gr.themes.Soft().set(button_primary_background_fill='#6562F4') with gr.Blocks(CIMStheme) as iface: with gr.Row(): with gr.Column(): gr.Markdown(value="