dwipper's picture
Update app.py
8af129a
raw
history blame contribute delete
No virus
3.23 kB
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'<span style="display: inline-block; position: relative; z-index: var(--layer-4); border: solid var(--block-title-border-width) var(--block-title-border-color); border-radius: var(--block-title-radius); background: var(--block-title-background-fill); padding: var(--block-title-padding); color: var(--block-title-text-color); font-weight: var(--block-title-text-weight); font-size: var(--block-title-text-size); line-height: var(--line-sm); margin-bottom: var(--spacing-lg);">{label_text}</span>'
#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="<H2 style='text-align: center;'>NILI - Powered by CIMS.AI</h2>")
with gr.Row():
with gr.Column(variant='panel'):
question_tbox= gr.components.Textbox(lines=3, placeholder="Enter your question here", label="NIL Question",info="Depending the scope of your question, results may take 30-60 sec.",interactive=True)
with gr.Row(variant='panel'):
with gr.Column():
examples_cmpt= gr.Examples(examples=get_examples(),inputs=question_tbox,label="Sample NIL questions - Click to select one",api_name="load_examples",examples_per_page=2)
with gr.Row():
with gr.Column():
gr.Markdown(value="[Ask Questions/Provide Feedback](https://discord.com/channels/1168589934244929647/1168589934244929650)")
with gr.Row():
with gr.Column():
gr.HTML('<center><i>© 2023 Collegiate Influencer Marketing Systems, Inc.</i><br>CIMS.AI, CIMS.AI logo, NILI, NILI logo, and EzNIL are trademarks of Collegiate Influencer Marketing Systems, Inc.</center>')
iface.launch()