Update app.py
Browse files
app.py
CHANGED
|
@@ -30,7 +30,7 @@ def get_chemical_info(chemical_name):
|
|
| 30 |
|
| 31 |
final_text = "\n".join(output)
|
| 32 |
|
| 33 |
-
# Save to
|
| 34 |
file_path = f"/tmp/{chemical_name.replace(' ', '_')}_info.txt"
|
| 35 |
with open(file_path, "w") as f:
|
| 36 |
f.write(final_text)
|
|
@@ -41,17 +41,21 @@ def get_chemical_info(chemical_name):
|
|
| 41 |
return f"No information found for '{chemical_name}'. Please try a more precise name.", None
|
| 42 |
|
| 43 |
|
| 44 |
-
# Gradio
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
)
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
final_text = "\n".join(output)
|
| 32 |
|
| 33 |
+
# Save to file
|
| 34 |
file_path = f"/tmp/{chemical_name.replace(' ', '_')}_info.txt"
|
| 35 |
with open(file_path, "w") as f:
|
| 36 |
f.write(final_text)
|
|
|
|
| 41 |
return f"No information found for '{chemical_name}'. Please try a more precise name.", None
|
| 42 |
|
| 43 |
|
| 44 |
+
# Gradio Blocks UI
|
| 45 |
+
with gr.Blocks(title="ChemQuery: Learn Molecules Easily") as demo:
|
| 46 |
+
gr.Markdown("## ChemQuery: Learn Molecules Easily")
|
| 47 |
+
gr.Markdown(
|
| 48 |
+
"Enter a chemical name to get formula, synonyms, atomic structure, and more. "
|
| 49 |
+
"Powered by PubChem & PubChemPy. Designed for student use in chemistry learning."
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
with gr.Row():
|
| 53 |
+
chemical_input = gr.Textbox(label="Enter Chemical Name", scale=2, lines=1)
|
| 54 |
+
submit_btn = gr.Button("Submit", scale=1)
|
| 55 |
+
|
| 56 |
+
output_text = gr.Textbox(label="Compound Information", lines=25)
|
| 57 |
+
download_file = gr.File(label="Download as TXT")
|
| 58 |
+
|
| 59 |
+
submit_btn.click(get_chemical_info, inputs=chemical_input, outputs=[output_text, download_file])
|
| 60 |
+
|
| 61 |
+
demo.launch()
|