MrAlvaroA commited on
Commit
af9d730
·
verified ·
1 Parent(s): 75f707d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -0
app.py CHANGED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+ import pandas as pd
4
+ import gradio as gr
5
+ from openai import OpenAI
6
+ from google.colab import userdata, drive
7
+ from langchain_community.embeddings.sentence_transformer import SentenceTransformerEmbeddings
8
+ from langchain_community.vectorstores import Chroma
9
+
10
+ client=OpenAI(
11
+ api_key=os.getenv("OPENAI_API_KEY")
12
+ )
13
+
14
+ model_name = 'gpt-3.5-turbo'
15
+ embedding_model = SentenceTransformerEmbeddings(model_name="thenlper/gte-large")
16
+ persisted_vectordb_location = '/vector_db/'
17
+ collection_name = 'companies-10K-2023'
18
+
19
+ vectorstore_persisted = Chroma(
20
+ collection_name=collection_name,
21
+ embedding_function=embedding_model,
22
+ persist_directory=persisted_vectordb_location
23
+ )
24
+
25
+ source = set()
26
+ document_names = set()
27
+
28
+ for metadata in stored_documents['metadatas']:
29
+ # Extract the source and use os.path.basename to get only the file name
30
+ source = metadata.get('source', 'No source found')
31
+ document_names.add(os.path.basename(source))
32
+
33
+ document_list = list(document_names)
34
+ document_list.insert(0, "All Documents")
35
+
36
+ with gr.Blocks() as demo:
37
+ with gr.Row():
38
+ with gr.Column(scale=1):
39
+
40
+ document_dropdown = gr.Dropdown(
41
+ choices=document_list,
42
+ label="Document",
43
+ )
44
+
45
+
46
+ temperature_slider = gr.Slider(
47
+ minimum=0,
48
+ maximum=1,
49
+ step=0.1,
50
+ #value=0.3,
51
+ label="Temperature",
52
+ info="Controls randomness: 0 = deterministic, 1 = creative/unexpected answers. If you can't get an answer try increasing the temperature but keep in mind that the accuracy can lower by doing this."
53
+ )
54
+
55
+
56
+ question_input = gr.Textbox(
57
+ label="Enter your question",
58
+ placeholder="Type your question here..."
59
+ )
60
+
61
+
62
+ analyze_button = gr.Button("Analyze and Answer")
63
+
64
+ with gr.Column(scale=1):
65
+ status_button = gr.Button(value="Ready", interactive=False, elem_id="status_button")
66
+
67
+ # Read-only textbox for Question Analysis
68
+ question_analysis_output = gr.Textbox(
69
+ label="Question Analysis",
70
+ placeholder="The analysis will be shown here...",
71
+ interactive=False
72
+ )
73
+
74
+ with gr.Row():
75
+ final_answer_output = gr.Textbox(
76
+ label="Final Answer",
77
+ placeholder="The final answer will be shown here...",
78
+ interactive=False
79
+ )
80
+
81
+ # Button click action to call the analyze_and_answer function
82
+ #analyze_button.click(
83
+ # analyze_and_answer,
84
+ # inputs=[document_dropdown, temperature_slider, question_input],
85
+ # outputs=[question_analysis_output, final_answer_output]
86
+ #)
87
+
88
+ demo.launch()