Rahatara commited on
Commit
64864b8
1 Parent(s): ddf2da0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -42
app.py CHANGED
@@ -23,7 +23,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
  SOFTWARE.
25
  """
26
-
27
  from typing import Any
28
  import gradio as gr
29
  from langchain_openai import OpenAIEmbeddings
@@ -38,36 +37,21 @@ import fitz
38
  from PIL import Image
39
  import os
40
  import re
41
- import uuid
42
 
43
  openai.api_key = "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"
44
 
45
- enable_box = gr.Textbox(
46
- value=None, placeholder="Upload your OpenAI API key", interactive=True
47
- )
48
- disable_box = gr.Textbox(value="OpenAI API key is set", interactive=False)
49
-
50
-
51
- def set_apikey(api_key: str):
52
- print("API Key set")
53
- app.OPENAI_API_KEY = api_key
54
- return disable_box
55
-
56
-
57
- def enable_api_box():
58
- return enable_box
59
-
60
 
61
  def add_text(history, text: str):
62
  if not text:
63
- raise gr.Error("enter text")
64
  history = history + [(text, "")]
65
  return history
66
 
67
 
68
- class my_app:
69
- def __init__(self, OPENAI_API_KEY: str = None) -> None:
70
- self.OPENAI_API_KEY: str = OPENAI_API_KEY
71
  self.chain = None
72
  self.chat_history: list = []
73
  self.N: int = 0
@@ -145,19 +129,11 @@ def purge_chat_and_render_first(file):
145
  image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
146
  return image, []
147
 
148
- app = my_app()
 
149
 
150
  with gr.Blocks() as demo:
151
  with gr.Column():
152
- with gr.Row():
153
-
154
- with gr.Column(scale=1):
155
- api_key = gr.Textbox(
156
- placeholder="Enter OpenAI API key and hit <RETURN>",
157
- show_label=False,
158
- interactive=True
159
- )
160
-
161
  with gr.Row():
162
  with gr.Column(scale=2):
163
  with gr.Row():
@@ -168,21 +144,13 @@ with gr.Blocks() as demo:
168
  placeholder="Enter text and press submit",
169
  scale=2
170
  )
171
- submit_btn = gr.Button("submit", scale=1)
172
 
173
  with gr.Column(scale=1):
174
  with gr.Row():
175
  show_img = gr.Image(label="Upload PDF")
176
  with gr.Row():
177
- btn = gr.UploadButton("📁 upload a PDF", file_types=[".pdf"])
178
-
179
- api_key.submit(
180
- fn=set_apikey,
181
- inputs=[api_key],
182
- outputs=[
183
- api_key,
184
- ],
185
- )
186
 
187
  btn.upload(
188
  fn=purge_chat_and_render_first,
@@ -204,4 +172,6 @@ with gr.Blocks() as demo:
204
  )
205
 
206
  demo.queue()
207
- demo.launch()
 
 
 
23
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
  SOFTWARE.
25
  """
 
26
  from typing import Any
27
  import gradio as gr
28
  from langchain_openai import OpenAIEmbeddings
 
37
  from PIL import Image
38
  import os
39
  import re
40
+ import openai
41
 
42
  openai.api_key = "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"
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  def add_text(history, text: str):
46
  if not text:
47
+ raise gr.Error("Enter text")
48
  history = history + [(text, "")]
49
  return history
50
 
51
 
52
+ class MyApp:
53
+ def __init__(self) -> None:
54
+ self.OPENAI_API_KEY: str = openai.api_key
55
  self.chain = None
56
  self.chat_history: list = []
57
  self.N: int = 0
 
129
  image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
130
  return image, []
131
 
132
+
133
+ app = MyApp()
134
 
135
  with gr.Blocks() as demo:
136
  with gr.Column():
 
 
 
 
 
 
 
 
 
137
  with gr.Row():
138
  with gr.Column(scale=2):
139
  with gr.Row():
 
144
  placeholder="Enter text and press submit",
145
  scale=2
146
  )
147
+ submit_btn = gr.Button("Submit", scale=1)
148
 
149
  with gr.Column(scale=1):
150
  with gr.Row():
151
  show_img = gr.Image(label="Upload PDF")
152
  with gr.Row():
153
+ btn = gr.UploadButton("📁 Upload a PDF", file_types=[".pdf"])
 
 
 
 
 
 
 
 
154
 
155
  btn.upload(
156
  fn=purge_chat_and_render_first,
 
172
  )
173
 
174
  demo.queue()
175
+ demo.launch()
176
+
177
+