Spaces:
Build error
Build error
File size: 1,583 Bytes
78c7928 55337be 863468c e957795 55337be 1c2a142 8f36df1 55337be a9d652e 55337be |
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 |
import gradio as gr
import openai
import os
# Ensure the OPENAI_API_KEY environment variable is set correctly
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
def generate_text(prompt):
# Add custom text to the prompt
input_text = (prompt + " You are an expert with many years of experience in the insurance loss adjusting business. "
"Can you give your expert opinion on the question or statement made at the start of this prompt? "
"Answer it in terms of the laws, regulations, and terms of the insurance industry. "
"Make it accurate, but written in a simple and clear style. "
"Please provide references or insurance law precedents where possible.")
# Generate text using OpenAI API. Adjust "model" to the latest available or desired model.
response = openai.Completion.create(
model="gpt-3.5-turbo", # Update this to the latest model you wish to use
prompt=input_text,
max_tokens=1024,
n=1,
stop=None,
temperature=0.7
)
# Return the generated text
return response.choices[0].text.strip()
# Define the Gradio interface using the updated syntax
iface = gr.Interface(
fn=generate_text,
inputs=gr.Textbox(lines=5, label="What do you wish to know about insurance?"),
outputs=gr.Textbox(label="Generated text:"),
title="AI Adjuster",
description="AI tool to help you understand and answer any insurance-related queries."
)
# Run the Gradio app
iface.launch()
|