Spaces:
Sleeping
Sleeping
louiismiro
commited on
Commit
•
3c4ebcd
1
Parent(s):
70a1383
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Define model name
|
5 |
+
MODEL_NAME = "jojo-ai-mst/MyanmarGPT-Chat"
|
6 |
+
|
7 |
+
# Load the tokenizer and model
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
10 |
+
MODEL_NAME,
|
11 |
+
torch_dtype="float32", # Optimized for CPU usage
|
12 |
+
low_cpu_mem_usage=True # Helps with limited memory
|
13 |
+
)
|
14 |
+
|
15 |
+
# Chatbot function
|
16 |
+
def chatbot(prompt):
|
17 |
+
inputs = tokenizer(prompt, return_tensors="pt") # Tokenize the input text
|
18 |
+
outputs = model.generate(
|
19 |
+
inputs.input_ids,
|
20 |
+
max_new_tokens=150, # Limit response length
|
21 |
+
temperature=0.7, # Control randomness
|
22 |
+
top_p=0.9 # Nucleus sampling
|
23 |
+
)
|
24 |
+
# Decode and return the generated text
|
25 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
26 |
+
return response
|
27 |
+
|
28 |
+
# Gradio interface
|
29 |
+
interface = gr.Interface(
|
30 |
+
fn=chatbot,
|
31 |
+
inputs=gr.Textbox(
|
32 |
+
label="Chat with Burmese ChatGPT",
|
33 |
+
placeholder="Type your message here in Burmese...",
|
34 |
+
lines=5
|
35 |
+
),
|
36 |
+
outputs=gr.Textbox(label="Response"),
|
37 |
+
title="Burmese ChatGPT",
|
38 |
+
description="A chatbot powered by MyanmarGPT-Chat for Burmese conversations."
|
39 |
+
)
|
40 |
+
|
41 |
+
# Launch the interface
|
42 |
+
if __name__ == "__main__":
|
43 |
+
interface.launch()
|