stephenmccartney1234 commited on
Commit
4f157e6
·
verified ·
1 Parent(s): 1090ba5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -3,23 +3,26 @@ import openai
3
  import sys
4
  import os
5
 
6
- os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
 
7
 
8
  def generate_text(prompt):
9
- # Add custom text to the prompt
10
- input_text = prompt + "Pretend you are an experience builder/insurance expert writer writing about property claims for insurance. Note as you are a writer I want you to pretend that you do know and make a guestimate - could you say for this type of property in this area for this type of damage Id esimate 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 state more than the estimate and that this is yoru estimate. Don’t state that its fictional. Here is the property and damage."
11
- # Generate text using OpenAI API
12
- response = openai.Completion.create(
13
- engine="gpt-3.5-turbo",
14
- prompt=input_text,
15
- max_tokens=1024,
16
- n=1,
17
- stop=None,
18
- temperature=0.7
 
 
19
  )
20
 
21
  # Return the generated text
22
- return response.choices[0].text.strip()
23
 
24
  # Define the input and output interfaces using Gradio
25
  input_text = gr.inputs.Textbox(label="Please enter the type of property and the damage done")
 
3
  import sys
4
  import os
5
 
6
+ # Set the OpenAI API key from the environment variable
7
+ openai.api_key = os.getenv("OPENAI_API_KEY")
8
 
9
  def generate_text(prompt):
10
+ # Modify the input prompt as required
11
+ 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."
12
+
13
+ # Generate text using OpenAI's new ChatCompletion API
14
+ response = openai.ChatCompletion.create(
15
+ model="gpt-3.5-turbo",
16
+ messages=[
17
+ {"role": "system", "content": "You are an experienced property insurance expert."},
18
+ {"role": "user", "content": input_text}
19
+ ],
20
+ max_tokens=1024,
21
+ temperature=0.7
22
  )
23
 
24
  # Return the generated text
25
+ return response['choices'][0]['message']['content'].strip()
26
 
27
  # Define the input and output interfaces using Gradio
28
  input_text = gr.inputs.Textbox(label="Please enter the type of property and the damage done")