Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,25 +3,24 @@ from transformers import pipeline
|
|
| 3 |
import torch
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# Ottieni il token dalle secrets dello Space
|
| 7 |
hf_token = os.environ.get("HF_TOKEN")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
print("
|
| 11 |
pipe = pipeline(
|
| 12 |
"text-generation",
|
| 13 |
model="google/txgemma-2b-predict",
|
| 14 |
-
device="cpu",
|
| 15 |
torch_dtype=torch.float32,
|
| 16 |
-
token=hf_token
|
| 17 |
)
|
| 18 |
|
| 19 |
def process_prompt(user_input):
|
| 20 |
"""
|
| 21 |
-
|
| 22 |
"""
|
| 23 |
try:
|
| 24 |
-
#
|
| 25 |
outputs = pipe(
|
| 26 |
user_input,
|
| 27 |
max_new_tokens=256,
|
|
@@ -33,7 +32,7 @@ def process_prompt(user_input):
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Errore durante l'elaborazione: {str(e)}"
|
| 35 |
|
| 36 |
-
#
|
| 37 |
demo = gr.Interface(
|
| 38 |
fn=process_prompt,
|
| 39 |
inputs=gr.Textbox(
|
|
@@ -54,6 +53,14 @@ demo = gr.Interface(
|
|
| 54 |
theme="soft"
|
| 55 |
)
|
| 56 |
|
| 57 |
-
#
|
| 58 |
if __name__ == "__main__":
|
| 59 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import torch
|
| 4 |
import os
|
| 5 |
|
|
|
|
| 6 |
hf_token = os.environ.get("HF_TOKEN")
|
| 7 |
|
| 8 |
+
# Load model TxGemma-2B
|
| 9 |
+
print("Load model TxGemma...")
|
| 10 |
pipe = pipeline(
|
| 11 |
"text-generation",
|
| 12 |
model="google/txgemma-2b-predict",
|
| 13 |
+
device="cpu",
|
| 14 |
torch_dtype=torch.float32,
|
| 15 |
+
token=hf_token
|
| 16 |
)
|
| 17 |
|
| 18 |
def process_prompt(user_input):
|
| 19 |
"""
|
| 20 |
+
Processing
|
| 21 |
"""
|
| 22 |
try:
|
| 23 |
+
# Generate response
|
| 24 |
outputs = pipe(
|
| 25 |
user_input,
|
| 26 |
max_new_tokens=256,
|
|
|
|
| 32 |
except Exception as e:
|
| 33 |
return f"Errore durante l'elaborazione: {str(e)}"
|
| 34 |
|
| 35 |
+
# Create Interface
|
| 36 |
demo = gr.Interface(
|
| 37 |
fn=process_prompt,
|
| 38 |
inputs=gr.Textbox(
|
|
|
|
| 53 |
theme="soft"
|
| 54 |
)
|
| 55 |
|
| 56 |
+
# Launch app
|
| 57 |
if __name__ == "__main__":
|
| 58 |
demo.launch()
|
| 59 |
+
|
| 60 |
+
# After load of the model
|
| 61 |
+
model_info = f"""
|
| 62 |
+
**Model load:** {pipe.model.config._name_or_path}
|
| 63 |
+
**Type:** {pipe.model.config.model_type}
|
| 64 |
+
**Parameters:** {pipe.model.num_parameters() / 1e9:.2f}B
|
| 65 |
+
**Spec:** Therapeutic Development (TDC)
|
| 66 |
+
"""
|