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()