import gradio as gr import openai import sys import os 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 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 response = openai.Completion.create( engine="text-davinci-002", 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 input and output interfaces using Gradio input_text = gr.inputs.Textbox(label="What do you wish to know about insurance") 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="AI Adjuster", description="AI tool to help you understand and answer any insurance related queries." ) gradio_app.launch()