DSDUDEd commited on
Commit
3322dd2
·
verified ·
1 Parent(s): bf357c2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+
4
+ # Load your model
5
+ tokenizer = AutoTokenizer.from_pretrained("colorfulscoop/gpt2-small-ja")
6
+ model = AutoModelForCausalLM.from_pretrained("colorfulscoop/gpt2-small-ja")
7
+
8
+ # Function to generate AI response
9
+ def generate(text):
10
+ inputs = tokenizer(text, return_tensors="pt")
11
+ outputs = model.generate(**inputs, max_new_tokens=50)
12
+ return tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])
13
+
14
+ # Gradio interface
15
+ iface = gr.Interface(
16
+ fn=generate,
17
+ inputs="text",
18
+ outputs="text",
19
+ title="Japanese GPT-2 Chatbot",
20
+ description="Type a message in Japanese and get a response."
21
+ )
22
+
23
+ iface.launch()