vortexa64 commited on
Commit
b47f904
·
verified ·
1 Parent(s): 560931f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ # Pakai model Indo ya sayang 🤭
6
+ model_id = "cahya/gpt2-small-indonesian-522M"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
8
+ model = AutoModelForCausalLM.from_pretrained(model_id)
9
+
10
+ chat_history = []
11
+
12
+ def chat(user_input):
13
+ global chat_history
14
+ input_text = " ".join(chat_history + [user_input])
15
+
16
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
17
+ output_ids = model.generate(
18
+ input_ids,
19
+ max_length=200,
20
+ pad_token_id=tokenizer.eos_token_id,
21
+ do_sample=True,
22
+ top_k=50,
23
+ top_p=0.95,
24
+ temperature=0.7
25
+ )
26
+ response = tokenizer.decode(output_ids[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
27
+ chat_history.append(user_input)
28
+ chat_history.append(response)
29
+ return response
30
+
31
+ iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="Cici Chat Indo 🤭💕")
32
+ iface.launch()