Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load the pre-trained model and tokenizer
|
6 |
+
model_name = "khanfs/ChemSolubilityBERTa"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
9 |
+
|
10 |
+
# Define the prediction function
|
11 |
+
def predict_solubility(smiles_string):
|
12 |
+
inputs = tokenizer(smiles_string, return_tensors='pt', truncation=True, padding='max_length', max_length=128)
|
13 |
+
with torch.no_grad():
|
14 |
+
outputs = model(**inputs)
|
15 |
+
solubility = outputs.logits.item()
|
16 |
+
return f"Predicted Solubility: {solubility:.4f} log mol/L"
|
17 |
+
|
18 |
+
# Gradio interface
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=predict_solubility,
|
21 |
+
inputs="text",
|
22 |
+
outputs="text",
|
23 |
+
title="ChemSolubilityBERTa",
|
24 |
+
description="Enter a SMILES string to predict its aqueous solubility using ChemSolubilityBERTa.",
|
25 |
+
examples=[["CCO"], ["CC(C)=O"], ["C1=CC=CC=C1"]] # Example SMILES strings for ethanol, acetone, and benzene
|
26 |
+
)
|
27 |
+
|
28 |
+
# Launch the app
|
29 |
+
iface.launch()
|