Spaces:
Sleeping
Sleeping
Commit
·
3ffe848
1
Parent(s):
591425a
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,21 +13,33 @@ import gradio as gr
|
|
| 13 |
#model = AutoModel.from_pretrained("medicalai/ClinicalBERT")
|
| 14 |
|
| 15 |
|
| 16 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Esempio di utilizzo del modello
|
| 23 |
inputs = tokenizer("Esempio di testo da classificare", return_tensors="pt")
|
| 24 |
outputs = model(**inputs)
|
| 25 |
|
| 26 |
# Define a function to generate text using the model
|
| 27 |
-
def generate_text(input_text):
|
| 28 |
-
input_ids = tokenizer.encode(input_text, return_tensors='pt')
|
| 29 |
-
output = model.generate(input_ids)
|
| 30 |
-
return tokenizer.decode(output[0], skip_special_tokens=True)
|
| 31 |
|
| 32 |
interface = gr.Interface(fn=generate_text, inputs="text", outputs="text")
|
| 33 |
|
|
|
|
| 13 |
#model = AutoModel.from_pretrained("medicalai/ClinicalBERT")
|
| 14 |
|
| 15 |
|
| 16 |
+
#from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 17 |
+
#tokenizer = AutoTokenizer.from_pretrained("emilyalsentzer/Bio_ClinicalBERT")
|
| 18 |
+
#model = AutoModelForSequenceClassification.from_pretrained("emilyalsentzer/Bio_ClinicalBERT", num_labels=2)
|
| 19 |
|
| 20 |
+
|
| 21 |
+
import gradio as gr
|
| 22 |
+
from transformers import pipeline
|
| 23 |
+
|
| 24 |
+
# Carica il modello
|
| 25 |
+
model = pipeline("text-generation", model="emilyalsentzer/Bio_ClinicalBERT")
|
| 26 |
+
|
| 27 |
+
# Definisci la funzione per generare il testo
|
| 28 |
+
def generate_text(prompt):
|
| 29 |
+
return model(prompt, max_length=50)[0]['generated_text']
|
| 30 |
+
|
| 31 |
+
# Crea l'interfaccia
|
| 32 |
+
interface = gr.Interface(fn=generate_text, inputs="text", outputs="text")
|
| 33 |
|
| 34 |
# Esempio di utilizzo del modello
|
| 35 |
inputs = tokenizer("Esempio di testo da classificare", return_tensors="pt")
|
| 36 |
outputs = model(**inputs)
|
| 37 |
|
| 38 |
# Define a function to generate text using the model
|
| 39 |
+
#def generate_text(input_text):
|
| 40 |
+
# input_ids = tokenizer.encode(input_text, return_tensors='pt')
|
| 41 |
+
# output = model.generate(input_ids)
|
| 42 |
+
# return tokenizer.decode(output[0], skip_special_tokens=True)
|
| 43 |
|
| 44 |
interface = gr.Interface(fn=generate_text, inputs="text", outputs="text")
|
| 45 |
|