Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,43 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
3 |
|
4 |
-
# Load
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
tokenizer = AutoTokenizer.from_pretrained("viv/UD_Greek-GUD")
|
6 |
-
model = AutoModelForTokenClassification.from_pretrained("viv/UD_Greek-GUD")
|
7 |
|
|
|
8 |
def predict(text):
|
9 |
inputs = tokenizer(text, return_tensors="pt")
|
10 |
outputs = model(**inputs)
|
|
|
11 |
return outputs.logits.argmax(-1).tolist()
|
12 |
|
13 |
-
# Interface
|
14 |
interface = gr.Interface(
|
15 |
fn=predict,
|
16 |
inputs="text",
|
17 |
outputs="text",
|
18 |
title="UD Greek GUD Model",
|
19 |
-
description="
|
20 |
)
|
21 |
|
|
|
22 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification, AutoConfig
|
3 |
|
4 |
+
# Load configuration manually if it's missing in the repository
|
5 |
+
try:
|
6 |
+
config = AutoConfig.from_pretrained("viv/UD_Greek-GUD")
|
7 |
+
except OSError:
|
8 |
+
# Fallback: Create a configuration manually
|
9 |
+
config = AutoConfig.from_dict({
|
10 |
+
"model_type": "bert", # Change this based on your model type
|
11 |
+
"hidden_size": 768,
|
12 |
+
"num_attention_heads": 12,
|
13 |
+
"num_hidden_layers": 12,
|
14 |
+
"vocab_size": 30000,
|
15 |
+
"max_position_embeddings": 512,
|
16 |
+
"type_vocab_size": 2,
|
17 |
+
"hidden_act": "gelu",
|
18 |
+
"layer_norm_eps": 1e-12,
|
19 |
+
"initializer_range": 0.02
|
20 |
+
})
|
21 |
+
|
22 |
+
# Load model and tokenizer with the provided or fallback config
|
23 |
tokenizer = AutoTokenizer.from_pretrained("viv/UD_Greek-GUD")
|
24 |
+
model = AutoModelForTokenClassification.from_pretrained("viv/UD_Greek-GUD", config=config)
|
25 |
|
26 |
+
# Prediction function
|
27 |
def predict(text):
|
28 |
inputs = tokenizer(text, return_tensors="pt")
|
29 |
outputs = model(**inputs)
|
30 |
+
# Process and return predictions
|
31 |
return outputs.logits.argmax(-1).tolist()
|
32 |
|
33 |
+
# Gradio Interface
|
34 |
interface = gr.Interface(
|
35 |
fn=predict,
|
36 |
inputs="text",
|
37 |
outputs="text",
|
38 |
title="UD Greek GUD Model",
|
39 |
+
description="Analyze text using the UD Greek GUD model.",
|
40 |
)
|
41 |
|
42 |
+
# Launch interface
|
43 |
interface.launch()
|