robertselvam
commited on
Commit
•
30b8f16
1
Parent(s):
a43d105
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ import re
|
|
21 |
class ChemicalIdentifier:
|
22 |
def __init__(self):
|
23 |
|
24 |
-
openai.api_key = os.getenv("OPENAI_API_KEY")
|
25 |
self.logger = logging.getLogger("ChemicalIdentifier")
|
26 |
self.logger.setLevel(logging.DEBUG)
|
27 |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
@@ -246,8 +246,10 @@ class ChemicalIdentifier:
|
|
246 |
|
247 |
return data_list
|
248 |
|
249 |
-
def comparing_chemicals(self,
|
250 |
-
|
|
|
|
|
251 |
response = openai.Completion.create(
|
252 |
engine="text-davinci-003",
|
253 |
prompt= f"""Analyse the following text delimited by triple backticks to return the comman chemicals.
|
@@ -274,48 +276,35 @@ class ChemicalIdentifier:
|
|
274 |
|
275 |
try:
|
276 |
with gr.Blocks(css="style.css",theme='karthikeyan-adople/hudsonhayes-dark1') as demo:
|
277 |
-
|
278 |
-
gr.HTML("""<center><div class="crop"> <img src="file=logo.png" alt="logo"/></div></center>""")
|
279 |
state = gr.State(self.get_empty_state())
|
280 |
-
gr.HTML("""<center><h1 style="color:#fff">Chemical Identifier
|
281 |
-
|
282 |
-
# chemicals_textbox = gr.Textbox(label="Chemicals",lines=6)
|
283 |
with gr.Column(elem_id="col-container"):
|
284 |
with gr.Row(elem_id="row-flex"):
|
285 |
url = gr.Textbox(label="URL")
|
286 |
with gr.Row(elem_id="row-flex"):
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
excel_input = gr.File(elem_classes="heightfit1",label = "excel file",file_types = [".xlsx"])
|
297 |
-
with gr.Row():
|
298 |
-
with gr.Column(scale=1, min_width=0):
|
299 |
-
analyse_btn = gr.Button(value="Analyse",variant="primary")
|
300 |
-
with gr.Row():
|
301 |
-
with gr.Column(scale=1, min_width=0):
|
302 |
-
answer = gr.Textbox(value="",label='Chemicals :',show_label=True, placeholder="",lines=5)
|
303 |
with gr.Row():
|
304 |
with gr.Column(scale=1, min_width=0):
|
305 |
-
compare_btn = gr.Button(value="
|
306 |
with gr.Row():
|
307 |
with gr.Column(scale=1, min_width=0):
|
308 |
-
compared_result = gr.Textbox(value="",label='
|
309 |
|
310 |
|
311 |
upload_button.upload(self.upload_file, upload_button, [file_output,state])
|
312 |
|
313 |
-
|
314 |
-
|
315 |
-
compare_btn.click(self.comparing_chemicals,[excel_input,answer],compared_result)
|
316 |
-
|
317 |
-
# btn.click(fn=self.get_chemicals, inputs=url, outputs=chemicals_textbox)
|
318 |
-
demo.launch()
|
319 |
|
320 |
except Exception as e:
|
321 |
self.logger.error("Error occurred while launching Gradio interface: %s", str(e))
|
@@ -324,4 +313,4 @@ class ChemicalIdentifier:
|
|
324 |
if __name__ == "__main__":
|
325 |
logging.basicConfig(level=logging.DEBUG)
|
326 |
chemical_identifier = ChemicalIdentifier()
|
327 |
-
chemical_identifier.gradio_interface()
|
|
|
21 |
class ChemicalIdentifier:
|
22 |
def __init__(self):
|
23 |
|
24 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
25 |
self.logger = logging.getLogger("ChemicalIdentifier")
|
26 |
self.logger.setLevel(logging.DEBUG)
|
27 |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
|
246 |
|
247 |
return data_list
|
248 |
|
249 |
+
def comparing_chemicals(self,urls,state):
|
250 |
+
chemicals = self.answer_question(urls,state)
|
251 |
+
excel_file_path = "/content/Capability.xlsx"
|
252 |
+
chemistry_capability = self.extract_excel_data(excel_file_path)
|
253 |
response = openai.Completion.create(
|
254 |
engine="text-davinci-003",
|
255 |
prompt= f"""Analyse the following text delimited by triple backticks to return the comman chemicals.
|
|
|
276 |
|
277 |
try:
|
278 |
with gr.Blocks(css="style.css",theme='karthikeyan-adople/hudsonhayes-dark1') as demo:
|
279 |
+
gr.HTML("""<center><img src="https://hudsonandhayes.co.uk/wp-content/uploads/2023/01/Group-479.svg" height="110px" width="280px"></center>""")
|
|
|
280 |
state = gr.State(self.get_empty_state())
|
281 |
+
gr.HTML("""<center><h1 style="color:#fff">Chemical Identifier</h1></center>""")
|
282 |
+
|
|
|
283 |
with gr.Column(elem_id="col-container"):
|
284 |
with gr.Row(elem_id="row-flex"):
|
285 |
url = gr.Textbox(label="URL")
|
286 |
with gr.Row(elem_id="row-flex"):
|
287 |
+
with gr.Accordion("Upload Files", open = False):
|
288 |
+
with gr.Row():
|
289 |
+
with gr.Column(scale=0.90, min_width=160):
|
290 |
+
file_output = gr.File()
|
291 |
+
with gr.Column(scale=0.10, min_width=160):
|
292 |
+
upload_button = gr.UploadButton(
|
293 |
+
"Browse File", file_types=[".txt", ".pdf", ".doc", ".docx"],
|
294 |
+
file_count = "multiple",variant="primary")
|
295 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
with gr.Row():
|
297 |
with gr.Column(scale=1, min_width=0):
|
298 |
+
compare_btn = gr.Button(value="Analyse",variant="primary")
|
299 |
with gr.Row():
|
300 |
with gr.Column(scale=1, min_width=0):
|
301 |
+
compared_result = gr.Textbox(value="",label='Chemicals :',show_label=True, placeholder="",lines=10)
|
302 |
|
303 |
|
304 |
upload_button.upload(self.upload_file, upload_button, [file_output,state])
|
305 |
|
306 |
+
compare_btn.click(self.comparing_chemicals,[url,state],compared_result)
|
307 |
+
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
308 |
|
309 |
except Exception as e:
|
310 |
self.logger.error("Error occurred while launching Gradio interface: %s", str(e))
|
|
|
313 |
if __name__ == "__main__":
|
314 |
logging.basicConfig(level=logging.DEBUG)
|
315 |
chemical_identifier = ChemicalIdentifier()
|
316 |
+
chemical_identifier.gradio_interface()
|