Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -73,50 +73,50 @@ def render_file(file):
|
|
73 |
return image
|
74 |
|
75 |
# Gradio application setup
|
76 |
-
with gr.Blocks() as demo:
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
|
100 |
|
101 |
-
def render_first(pdf_file):
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
|
106 |
-
with gr.Blocks() as demo:
|
107 |
-
|
108 |
|
109 |
-
|
110 |
|
111 |
-
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
# ).success(
|
121 |
# fn=generate_response,
|
122 |
# inputs=[chatbot, txt, btn],
|
@@ -126,6 +126,48 @@ with gr.Blocks() as demo:
|
|
126 |
# inputs=[btn],
|
127 |
# outputs=[show_img]
|
128 |
# )
|
129 |
-
demo.queue()
|
130 |
-
if __name__ == "__main__":
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
return image
|
74 |
|
75 |
# Gradio application setup
|
76 |
+
# with gr.Blocks() as demo:
|
77 |
+
# with gr.Column():
|
78 |
+
# gr.Markdown("""
|
79 |
+
# <style>
|
80 |
+
# .image-container { height: 680px; }
|
81 |
+
# </style>
|
82 |
+
# """)
|
83 |
+
# with gr.Row():
|
84 |
+
# enable_box = gr.Textbox(placeholder='Enter OpenAI API key',
|
85 |
+
# show_label=False, interactive=True)
|
86 |
+
# disable_box = gr.Textbox(value='OpenAI API key is Set', interactive=False)
|
87 |
+
# change_api_key = gr.Button('Change Key')
|
88 |
+
# with gr.Row():
|
89 |
+
# chatbot = gr.Chatbot(value=[], elem_id='chatbot')
|
90 |
+
# show_img = gr.Image(label='Upload PDF')
|
91 |
+
|
92 |
+
# # Set up event handlers
|
93 |
+
|
94 |
+
# # Event handler for submitting the OpenAI API key
|
95 |
+
# enable_box.submit(fn=set_apikey, inputs=[enable_box], outputs=[disable_box])
|
96 |
+
|
97 |
+
# # Event handler for changing the API key
|
98 |
+
# change_api_key.click(fn=enable_api_box, outputs=[enable_box])
|
99 |
|
100 |
|
101 |
+
# def render_first(pdf_file):
|
102 |
+
# # ... Logic to process the PDF
|
103 |
+
# # ... Generate the first image
|
104 |
+
# return image
|
105 |
|
106 |
+
# with gr.Blocks() as demo:
|
107 |
+
# # ... your UI setup ...
|
108 |
|
109 |
+
# pdf_upload = gr.UploadButton("π Upload a PDF", file_types=[".pdf"])
|
110 |
|
111 |
+
# # ... other event handlers ...
|
112 |
|
113 |
+
# pdf_upload.upload(fn=render_first, inputs=[pdf_upload], outputs=[show_img])
|
114 |
+
# # Event handler for submitting text and generating response
|
115 |
+
# submit_btn.click(
|
116 |
+
# fn=add_text,
|
117 |
+
# inputs=[chatbot, txt],
|
118 |
+
# outputs=[chatbot],
|
119 |
+
# queue=False
|
120 |
# ).success(
|
121 |
# fn=generate_response,
|
122 |
# inputs=[chatbot, txt, btn],
|
|
|
126 |
# inputs=[btn],
|
127 |
# outputs=[show_img]
|
128 |
# )
|
129 |
+
# demo.queue()
|
130 |
+
# if __name__ == "__main__":
|
131 |
+
# demo.launch()
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
+
with gr.Blocks() as demo:
|
136 |
+
with gr.Column():
|
137 |
+
gr.Markdown("""
|
138 |
+
<style>
|
139 |
+
.image-container { height: 680px; }
|
140 |
+
</style>
|
141 |
+
""")
|
142 |
+
with gr.Row():
|
143 |
+
enable_box = gr.Textbox(placeholder='Enter OpenAI API key',
|
144 |
+
show_label=False, interactive=True)
|
145 |
+
disable_box = gr.Textbox(value='OpenAI API key is Set', interactive=False)
|
146 |
+
change_api_key = gr.Button('Change Key')
|
147 |
+
with gr.Row():
|
148 |
+
chatbot = gr.Chatbot(value=[], elem_id='chatbot')
|
149 |
+
show_img = gr.Image(label='Upload PDF')
|
150 |
+
pdf_upload = gr.UploadButton("π Upload a PDF", file_types=[".pdf"]) # Added
|
151 |
+
|
152 |
+
# Event handlers
|
153 |
+
enable_box.submit(fn=set_apikey, inputs=[enable_box], outputs=[disable_box])
|
154 |
+
change_api_key.click(fn=enable_api_box, outputs=[enable_box])
|
155 |
+
pdf_upload.upload(fn=render_first, inputs=[pdf_upload], outputs=[show_img]) # Corrected
|
156 |
+
|
157 |
+
submit_btn = gr.Button('Submit') # Added the Submit button
|
158 |
+
submit_btn.click(
|
159 |
+
fn=add_text,
|
160 |
+
inputs=[chatbot, txt], # Assuming 'txt' is your textbox for query input
|
161 |
+
outputs=[chatbot],
|
162 |
+
queue=False
|
163 |
+
).success(
|
164 |
+
fn=generate_response,
|
165 |
+
inputs=[chatbot, txt, pdf_upload], # Changed from 'btn'
|
166 |
+
outputs=[chatbot, txt]
|
167 |
+
).success(
|
168 |
+
fn=render_file,
|
169 |
+
inputs=[pdf_upload], # Changed from 'btn'
|
170 |
+
outputs=[show_img]
|
171 |
+
)
|
172 |
+
|
173 |
+
demo.launch()
|