Rezuwan commited on
Commit
cfcf72b
·
verified ·
1 Parent(s): cefc489

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -28,16 +28,27 @@ def get_chemical_info(chemical_name):
28
  atom2 = atom_dict.get(bond.aid2, f"Atom {bond.aid2}")
29
  output.append(f" Bond between {atom1} and {atom2}, Order: {bond.order}")
30
 
31
- return "\n".join(output)
 
 
 
 
 
 
 
32
 
33
  except IndexError:
34
- return f"No information found for '{chemical_name}'. Please try a more precise name."
 
35
 
36
  # Gradio Interface
37
  demo = gr.Interface(
38
  fn=get_chemical_info,
39
  inputs=gr.Textbox(label="Enter Chemical Name"),
40
- outputs=gr.Textbox(label="Compound Information", lines=20),
 
 
 
41
  title="ChemQuery: Learn Molecules Easily",
42
  description="Enter a chemical name to get formula, synonyms, atomic structure, and more. Powered by PubChem & PubChemPy. Designed for student use in chemistry learning."
43
  )
 
28
  atom2 = atom_dict.get(bond.aid2, f"Atom {bond.aid2}")
29
  output.append(f" Bond between {atom1} and {atom2}, Order: {bond.order}")
30
 
31
+ final_text = "\n".join(output)
32
+
33
+ # Save to a file for download
34
+ file_path = f"/tmp/{chemical_name.replace(' ', '_')}_info.txt"
35
+ with open(file_path, "w") as f:
36
+ f.write(final_text)
37
+
38
+ return final_text, file_path
39
 
40
  except IndexError:
41
+ return f"No information found for '{chemical_name}'. Please try a more precise name.", None
42
+
43
 
44
  # Gradio Interface
45
  demo = gr.Interface(
46
  fn=get_chemical_info,
47
  inputs=gr.Textbox(label="Enter Chemical Name"),
48
+ outputs=[
49
+ gr.Textbox(label="Compound Information", lines=20),
50
+ gr.File(label="Download as TXT")
51
+ ],
52
  title="ChemQuery: Learn Molecules Easily",
53
  description="Enter a chemical name to get formula, synonyms, atomic structure, and more. Powered by PubChem & PubChemPy. Designed for student use in chemistry learning."
54
  )