Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ client=OpenAI(
|
|
| 11 |
)
|
| 12 |
|
| 13 |
model_name = 'gpt-3.5-turbo'
|
|
|
|
| 14 |
embedding_model = SentenceTransformerEmbeddings(model_name="thenlper/gte-large")
|
| 15 |
persisted_vectordb_location = './vector_db/'
|
| 16 |
collection_name = 'companies-10K-2023'
|
|
@@ -21,8 +22,38 @@ vectorstored_persisted = Chroma(
|
|
| 21 |
persist_directory=persisted_vectordb_location
|
| 22 |
)
|
| 23 |
|
| 24 |
-
stored_documents = vectorstored_persisted.get(include=["metadatas"])
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
source = set()
|
| 27 |
document_names = set()
|
| 28 |
|
|
@@ -64,8 +95,7 @@ with gr.Blocks() as demo:
|
|
| 64 |
|
| 65 |
with gr.Column(scale=1):
|
| 66 |
status_button = gr.Button(value="Ready", interactive=False, elem_id="status_button")
|
| 67 |
-
|
| 68 |
-
# Read-only textbox for Question Analysis
|
| 69 |
question_analysis_output = gr.Textbox(
|
| 70 |
label="Question Analysis",
|
| 71 |
placeholder="The analysis will be shown here...",
|
|
@@ -80,10 +110,9 @@ with gr.Blocks() as demo:
|
|
| 80 |
)
|
| 81 |
|
| 82 |
# Button click action to call the analyze_and_answer function
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
#)
|
| 88 |
|
| 89 |
demo.launch()
|
|
|
|
| 11 |
)
|
| 12 |
|
| 13 |
model_name = 'gpt-3.5-turbo'
|
| 14 |
+
rater_model = 'gpt-4o-mini'
|
| 15 |
embedding_model = SentenceTransformerEmbeddings(model_name="thenlper/gte-large")
|
| 16 |
persisted_vectordb_location = './vector_db/'
|
| 17 |
collection_name = 'companies-10K-2023'
|
|
|
|
| 22 |
persist_directory=persisted_vectordb_location
|
| 23 |
)
|
| 24 |
|
|
|
|
| 25 |
|
| 26 |
+
def analyze_question(question)
|
| 27 |
+
status_button.update(value="Analyzing")
|
| 28 |
+
with open('./templates/question_analysis.txt', 'r') as file:
|
| 29 |
+
question_analysis = file.read()
|
| 30 |
+
|
| 31 |
+
with open('./templates/question_analysis_template.txt', 'r') as file:
|
| 32 |
+
question_analysis_template = file.read()
|
| 33 |
+
|
| 34 |
+
q_analysis = [
|
| 35 |
+
{"role": "system", "content": question_analysis},
|
| 36 |
+
{"role": "user", "content": question_template.format(
|
| 37 |
+
question=question,
|
| 38 |
+
)
|
| 39 |
+
}
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
response = client.chat.completions.create(
|
| 44 |
+
model=model_name,
|
| 45 |
+
messages=q_analysis,
|
| 46 |
+
max_tokens=2000,
|
| 47 |
+
temperature=0.0
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
question_analysis_output.update(value=response.choices[0].message.content)
|
| 51 |
+
|
| 52 |
+
except openai.OpenAIError as e:
|
| 53 |
+
status_button.update(value=f"An error occurred: {str(e)}")
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
stored_documents = vectorstored_persisted.get(include=["metadatas"])
|
| 57 |
source = set()
|
| 58 |
document_names = set()
|
| 59 |
|
|
|
|
| 95 |
|
| 96 |
with gr.Column(scale=1):
|
| 97 |
status_button = gr.Button(value="Ready", interactive=False, elem_id="status_button")
|
| 98 |
+
|
|
|
|
| 99 |
question_analysis_output = gr.Textbox(
|
| 100 |
label="Question Analysis",
|
| 101 |
placeholder="The analysis will be shown here...",
|
|
|
|
| 110 |
)
|
| 111 |
|
| 112 |
# Button click action to call the analyze_and_answer function
|
| 113 |
+
analyze_button.click(
|
| 114 |
+
analyze_question,
|
| 115 |
+
inputs=question_input,
|
| 116 |
+
)
|
|
|
|
| 117 |
|
| 118 |
demo.launch()
|