Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,34 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import spaces
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
import spaces
|
4 |
+
# Load model and tokenizer
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("Yoxas/autotrain-test")
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("Yoxas/autotrain-test")
|
7 |
+
@spaces.GPU(duration=120)
|
8 |
|
9 |
+
def chatbot(input_text, input_token, temperature):
|
10 |
+
inputs = tokenizer.encode_plus(
|
11 |
+
input_text,
|
12 |
+
add_special_tokens=True,
|
13 |
+
max_length=512,
|
14 |
+
return_attention_mask=True,
|
15 |
+
return_tensors='pt'
|
16 |
+
)
|
17 |
+
outputs = model(inputs['input_ids'], attention_mask=inputs['attention_mask'])
|
18 |
+
last_hidden_state = outputs.last_hidden_state[:, 0, :]
|
19 |
+
response = tokenizer.decode(last_hidden_state, skip_special_tokens=True)
|
20 |
+
return response
|
21 |
+
|
22 |
+
# Create Gradio interface
|
23 |
+
interface = gr.Interface(
|
24 |
+
fn=chatbot,
|
25 |
+
inputs=[
|
26 |
+
gr.Textbox(label="Input Text"),
|
27 |
+
gr.Number(label="Input Token", value=1),
|
28 |
+
gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, value=0.5)
|
29 |
+
],
|
30 |
+
outputs=gr.Textbox(label="Response")
|
31 |
+
)
|
32 |
+
|
33 |
+
# Launch interface
|
34 |
+
interface.launch()
|