Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from transformers import
|
4 |
-
from
|
5 |
-
from generate import generate_text
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
vocab_size = tokenizer.vocab_size
|
|
|
10 |
|
11 |
-
|
12 |
-
model
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
inputs="text",
|
21 |
-
outputs="text",
|
22 |
-
title="🧠 EvoDecoder Chatbot",
|
23 |
-
description="Ask Evo anything. Powered by your trained EvoDecoder.").launch()
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from transformers import AutoTokenizer
|
4 |
+
from generate import load_model, generate_text
|
|
|
5 |
|
6 |
+
# Settings
|
7 |
+
MODEL_PATH = "evo_decoder.pt"
|
8 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
+
TOKENIZER_NAME = "gpt2" # Or your custom tokenizer
|
10 |
+
MAX_TOKENS = 50
|
11 |
+
|
12 |
+
# Load tokenizer & model
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_NAME)
|
14 |
vocab_size = tokenizer.vocab_size
|
15 |
+
model = load_model(vocab_size, MODEL_PATH, DEVICE)
|
16 |
|
17 |
+
def chat(prompt):
|
18 |
+
output = generate_text(model, tokenizer, prompt, max_new_tokens=MAX_TOKENS, device=DEVICE)
|
19 |
+
return output
|
20 |
|
21 |
+
# Gradio UI
|
22 |
+
iface = gr.Interface(fn=chat,
|
23 |
+
inputs=gr.Textbox(label="Ask Evo..."),
|
24 |
+
outputs=gr.Textbox(label="Evo's Response"),
|
25 |
+
title="🧠 EvoDecoder Chatbot",
|
26 |
+
description="A lightweight conversational model powered by EvoDecoder")
|
27 |
|
28 |
+
iface.launch()
|
|
|
|
|
|
|
|