Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -73,38 +73,7 @@ def render_file(file):
|
|
73 |
image = Image.frombytes('RGB', [pix.width, pix.height], pix.samples)
|
74 |
return image
|
75 |
|
76 |
-
#
|
77 |
-
# # with gr.Blocks() as demo:
|
78 |
-
# # with gr.Column():
|
79 |
-
# # gr.Markdown("""
|
80 |
-
# # <style>
|
81 |
-
# # .image-container { height: 680px; }
|
82 |
-
# # </style>
|
83 |
-
# # """)
|
84 |
-
# # with gr.Row():
|
85 |
-
# # enable_box = gr.Textbox(placeholder='Enter OpenAI API key',
|
86 |
-
# # show_label=False, interactive=True)
|
87 |
-
# # disable_box = gr.Textbox(value='OpenAI API key is Set', interactive=False)
|
88 |
-
# # change_api_key = gr.Button('Change Key')
|
89 |
-
# # with gr.Row():
|
90 |
-
# # chatbot = gr.Chatbot(value=[], elem_id='chatbot')
|
91 |
-
# # show_img = gr.Image(label='Upload PDF')
|
92 |
-
|
93 |
-
# # # Set up event handlers
|
94 |
-
|
95 |
-
# # # Event handler for submitting the OpenAI API key
|
96 |
-
# # enable_box.submit(fn=set_apikey, inputs=[enable_box], outputs=[disable_box])
|
97 |
-
|
98 |
-
# # # Event handler for changing the API key
|
99 |
-
# # change_api_key.click(fn=enable_api_box, outputs=[enable_box])
|
100 |
-
|
101 |
-
|
102 |
-
# def render_first(pdf_file):
|
103 |
-
# # ... Logic to process the PDF
|
104 |
-
# # ... Generate the first image
|
105 |
-
# return image
|
106 |
-
|
107 |
-
|
108 |
# with gr.Blocks() as demo:
|
109 |
# with gr.Column():
|
110 |
# gr.Markdown("""
|
@@ -113,37 +82,68 @@ def render_file(file):
|
|
113 |
# </style>
|
114 |
# """)
|
115 |
# with gr.Row():
|
116 |
-
# enable_box = gr.Textbox(placeholder='Enter OpenAI API key',
|
117 |
# show_label=False, interactive=True)
|
118 |
# disable_box = gr.Textbox(value='OpenAI API key is Set', interactive=False)
|
119 |
# change_api_key = gr.Button('Change Key')
|
120 |
# with gr.Row():
|
121 |
# chatbot = gr.Chatbot(value=[], elem_id='chatbot')
|
122 |
-
# show_img = gr.Image(label='Upload PDF')
|
123 |
-
|
|
|
124 |
|
125 |
-
#
|
126 |
-
#
|
127 |
-
|
128 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
|
148 |
# demo.launch(server_port=7861)
|
149 |
|
|
|
73 |
image = Image.frombytes('RGB', [pix.width, pix.height], pix.samples)
|
74 |
return image
|
75 |
|
76 |
+
# Gradio application setup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
# with gr.Blocks() as demo:
|
78 |
# with gr.Column():
|
79 |
# gr.Markdown("""
|
|
|
82 |
# </style>
|
83 |
# """)
|
84 |
# with gr.Row():
|
85 |
+
# enable_box = gr.Textbox(placeholder='Enter OpenAI API key',
|
86 |
# show_label=False, interactive=True)
|
87 |
# disable_box = gr.Textbox(value='OpenAI API key is Set', interactive=False)
|
88 |
# change_api_key = gr.Button('Change Key')
|
89 |
# with gr.Row():
|
90 |
# chatbot = gr.Chatbot(value=[], elem_id='chatbot')
|
91 |
+
# show_img = gr.Image(label='Upload PDF')
|
92 |
+
|
93 |
+
# # Set up event handlers
|
94 |
|
95 |
+
# # Event handler for submitting the OpenAI API key
|
96 |
+
# enable_box.submit(fn=set_apikey, inputs=[enable_box], outputs=[disable_box])
|
97 |
+
|
98 |
+
# # Event handler for changing the API key
|
99 |
+
# change_api_key.click(fn=enable_api_box, outputs=[enable_box])
|
100 |
+
|
101 |
+
|
102 |
+
def render_first(pdf_file):
|
103 |
+
# ... Logic to process the PDF
|
104 |
+
# ... Generate the first image
|
105 |
+
return image
|
106 |
+
|
107 |
+
|
108 |
+
with gr.Blocks() as demo:
|
109 |
+
with gr.Column():
|
110 |
+
gr.Markdown("""
|
111 |
+
<style>
|
112 |
+
.image-container { height: 680px; }
|
113 |
+
</style>
|
114 |
+
""")
|
115 |
+
with gr.Row():
|
116 |
+
enable_box = gr.Textbox(placeholder='Enter OpenAI API key',
|
117 |
+
show_label=False, interactive=True)
|
118 |
+
disable_box = gr.Textbox(value='OpenAI API key is Set', interactive=False)
|
119 |
+
change_api_key = gr.Button('Change Key')
|
120 |
+
with gr.Row():
|
121 |
+
chatbot = gr.Chatbot(value=[], elem_id='chatbot')
|
122 |
+
show_img = gr.Image(label='Upload PDF')
|
123 |
+
pdf_upload = gr.UploadButton("π Upload a PDF", file_types=[".pdf"]) # Added
|
124 |
+
|
125 |
+
# Event handlers
|
126 |
+
enable_box.submit(fn=set_apikey, inputs=[enable_box], outputs=[disable_box])
|
127 |
+
change_api_key.click(fn=enable_api_box, outputs=[enable_box])
|
128 |
+
pdf_upload.upload(fn=render_first, inputs=[pdf_upload], outputs=[show_img]) # Corrected
|
129 |
|
130 |
|
131 |
+
txt = gr.Textbox(label="Enter your query", placeholder="Ask a question...") # Add Textbox
|
132 |
+
submit_btn = gr.Button('Submit') # Added the Submit button
|
133 |
+
submit_btn.click(
|
134 |
+
fn=add_text,
|
135 |
+
inputs=[chatbot, txt], # Assuming 'txt' is your textbox for query input
|
136 |
+
outputs=[chatbot],
|
137 |
+
queue=False
|
138 |
+
).success(
|
139 |
+
fn=generate_response,
|
140 |
+
inputs=[chatbot, txt, pdf_upload], # Changed from 'btn'
|
141 |
+
outputs=[chatbot, txt]
|
142 |
+
).success(
|
143 |
+
fn=render_file,
|
144 |
+
inputs=[pdf_upload], # Changed from 'btn'
|
145 |
+
outputs=[show_img]
|
146 |
+
)
|
147 |
|
148 |
# demo.launch(server_port=7861)
|
149 |
|