AssessorAI / app.py
stephenmccartney1234's picture
Update app.py
4f157e6 verified
import gradio as gr
import openai
import sys
import os
# Set the OpenAI API key from the environment variable
openai.api_key = os.getenv("OPENAI_API_KEY")
def generate_text(prompt):
# Modify the input prompt as required
input_text = prompt + " Pretend you are an experienced builder/insurance expert writer writing about property claims for insurance. Make an educated guess: 'For this type of property in this area, for this type of damage, I’d estimate it to be [whatever estimate you come up with], but state what may make it vary. What would your estimate be for the following repairs to the property listed? Please compare your value to ESTIMATE but do not exceed the estimate, and that this is your estimate.' Don’t state that it's fictional. Here is the property and damage."
# Generate text using OpenAI's new ChatCompletion API
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are an experienced property insurance expert."},
{"role": "user", "content": input_text}
],
max_tokens=1024,
temperature=0.7
)
# Return the generated text
return response['choices'][0]['message']['content'].strip()
# Define the input and output interfaces using Gradio
input_text = gr.inputs.Textbox(label="Please enter the type of property and the damage done")
output_text = gr.outputs.Textbox(label="Generated text:")
# Create the Gradio app and run it
gradio_app = gr.Interface(
fn=generate_text,
inputs=input_text,
outputs=output_text,
title="AssessorAI Tool",
description="An AI that helps you validate if repair estimates are acceptable"
)
gradio_app.launch()