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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -30,7 +30,7 @@ def get_chemical_info(chemical_name):
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)
@@ -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 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
- )
55
-
56
- if __name__ == "__main__":
57
- demo.launch()
 
 
 
 
 
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()