Rezuwan commited on
Commit
411663c
·
verified ·
1 Parent(s): 2200ff2

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pubchempy as pcp
3
+
4
+ def get_chemical_info(chemical_name):
5
+ try:
6
+ compound = pcp.get_compounds(chemical_name, 'name')[0]
7
+
8
+ output = []
9
+ output.append(f"IUPAC Name: {compound.iupac_name}")
10
+ output.append(f"Common Name: {compound.synonyms[0]}")
11
+ output.append(f"Synonyms: {', '.join(compound.synonyms[:4])}")
12
+ output.append(f"Formula: {compound.molecular_formula}")
13
+ output.append(f"Molecular Weight: {compound.molecular_weight}")
14
+ output.append(f"Exact Molecular Weight: {compound.exact_mass}")
15
+ output.append(f"Isotope Atom Count: {compound.isotope_atom_count}")
16
+ output.append(f"Charge: {compound.charge}")
17
+
18
+ output.append("\nAtoms:")
19
+ for i, atom in enumerate(compound.atoms, start=1):
20
+ output.append(f" Atom {i}: Element = {atom.element}")
21
+
22
+ output.append("\nBonds:")
23
+ for bond in compound.bonds:
24
+ output.append(f" Bond between Atom {bond.a1} and Atom {bond.a2}, Order: {bond.order}")
25
+
26
+ return "\n".join(output)
27
+
28
+ except IndexError:
29
+ return f"No information found for '{chemical_name}'. Please try a more precise name."
30
+
31
+ # Gradio Interface
32
+ demo = gr.Interface(
33
+ fn=get_chemical_info,
34
+ inputs=gr.Textbox(label="Enter Chemical Name"),
35
+ outputs=gr.Textbox(label="Compound Information", lines=20),
36
+ title="ChemQuery: Learn Molecules Easily",
37
+ description="Enter a chemical name to get formula, synonyms, atomic structure, and more. Powered by PubChem & PubChemPy. Designed for student use in chemistry learning."
38
+ )
39
+
40
+ if __name__ == "__main__":
41
+ demo.launch()