Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,39 @@
|
|
| 1 |
-
from gpt_index import SimpleDirectoryReader, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
|
| 2 |
-
from langchain.chat_models import ChatOpenAI
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
#
|
| 7 |
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
| 17 |
-
|
| 18 |
-
# Initialize the LLM predictor with an updated model name if available
|
| 19 |
-
#llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, model_name="gpt-4", max_tokens=num_outputs)) # Updated to GPT-4 or latest available model
|
| 20 |
-
#llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
|
| 21 |
-
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, model_name="gpt-4", max_tokens=num_outputs))
|
| 22 |
-
|
| 23 |
-
# Load documents from the directory
|
| 24 |
-
documents = SimpleDirectoryReader(directory_path).load_data()
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
#
|
| 37 |
-
response
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
iface.launch(share=False)
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Ensure the OPENAI_API_KEY environment variable is set correctly
|
| 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 + " You are an expert with many years of experience in the insurance loss adjusting business. "
|
| 11 |
+
"Can you give your expert opinion on the question or statement made at the start of this prompt? "
|
| 12 |
+
"Answer it in terms of the laws, regulations, and terms of the insurance industry. "
|
| 13 |
+
"Make it accurate, but written in a simple and clear style. "
|
| 14 |
+
"Please provide references or insurance law precedents where possible.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# Generate text using OpenAI API. Adjust "model" to the latest available or desired model.
|
| 17 |
+
response = openai.Completion.create(
|
| 18 |
+
model="gpt-3.5-turbo", # Update this to the latest model you wish to use
|
| 19 |
+
prompt=input_text,
|
| 20 |
+
max_tokens=1024,
|
| 21 |
+
n=1,
|
| 22 |
+
stop=None,
|
| 23 |
+
temperature=0.7
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Return the generated text
|
| 27 |
+
return response.choices[0].text.strip()
|
| 28 |
+
|
| 29 |
+
# Define the Gradio interface using the updated syntax
|
| 30 |
+
iface = gr.Interface(
|
| 31 |
+
fn=generate_text,
|
| 32 |
+
inputs=gr.Textbox(lines=5, label="What do you wish to know about insurance?"),
|
| 33 |
+
outputs=gr.Textbox(label="Generated text:"),
|
| 34 |
+
title="AI Adjuster",
|
| 35 |
+
description="AI tool to help you understand and answer any insurance-related queries."
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Run the Gradio app
|
| 39 |
+
iface.launch()
|
|
|