File size: 1,671 Bytes
5ebaaf9
 
 
f241caf
 
 
5ebaaf9
5378217
 
5ebaaf9
 
 
5378217
f241caf
5378217
5ebaaf9
 
 
 
5378217
5ebaaf9
 
5378217
5ebaaf9
 
 
 
 
 
 
 
 
 
 
5378217
5ebaaf9
 
 
 
 
 
 
 
 
 
 
 
a755b4e
 
 
 
 
 
 
 
5ebaaf9
 
5378217
5ebaaf9
 
5378217
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import gradio as gr
from transformers import pipeline
import torch
import os

hf_token = os.environ.get("HF_TOKEN")

# Load model TxGemma-2B
print("Load model TxGemma...")
pipe = pipeline(
    "text-generation",
    model="google/txgemma-2b-predict",
    device="cpu",
    torch_dtype=torch.float32,
    token=hf_token 
)

def process_prompt(user_input):
    """
    Processing
    """
    try:
        # Generate response
        outputs = pipe(
            user_input, 
            max_new_tokens=256,
            do_sample=True,
            temperature=0.7
        )
        response = outputs[0]["generated_text"]
        return response
    except Exception as e:
        return f"Errore durante l'elaborazione: {str(e)}"

# Create Interface
demo = gr.Interface(
    fn=process_prompt,
    inputs=gr.Textbox(
        label="Inserisci il prompt per TxGemma",
        placeholder="Esempio: CCO (molecola di etanolo)",
        lines=5
    ),
    outputs=gr.Textbox(
        label="Risposta di TxGemma",
        lines=10
    ),
    title="Demo TxGemma - Analisi Molecolare",
    description="""
            Inserisci un prompt (es. stringa SMILES di una molecola) e TxGemma fornirà previsioni sulle proprietà terapeutiche.
            
            ---
            <br><br>
            **Created with ❤️ by Rocco for Giulio(GOD)**
        """,
    theme="soft"
)

# Launch app
if __name__ == "__main__":
    demo.launch()

# After load of the model
model_info = f"""
**Model load:** {pipe.model.config._name_or_path}  
**Type:** {pipe.model.config.model_type}  
**Parameters:** {pipe.model.num_parameters() / 1e9:.2f}B  
**Spec:** Therapeutic Development (TDC)
"""