Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
model_name = "mistralai/Mistral-7B-Instruct"
|
| 5 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
|
| 8 |
+
custom_responses = {
|
| 9 |
+
"ู
ู ุตูุนู": "ุชู
ุฅูุดุงุฆู ุจูุงุณุทุฉ ุฌูุฑุฌ.",
|
| 10 |
+
"ู
ูู ุจุฑู
ุฌู": "ู
ุจุฑู
ุฌู ูู ุฌูุฑุฌ.",
|
| 11 |
+
"ู
ุง ุงุณู
ู": "ุฃูุง Octagon 2.0.",
|
| 12 |
+
"ูู ูุฏูู ู
ุงููุ": "ูุนู
ุ ุฃูุง ู
ู
ููู ูุฌูุฑุฌ.",
|
| 13 |
+
"ู
ุง ูู ูุฏููุ": "ูุฏูู ูู ุชูุฏูู
ุงูู
ุณุงุนุฏุฉ ูุงูุฅุฌุงุจุฉ ุนูู ุฃุณุฆูุชู ุจุฃูุถู ุทุฑููุฉ ู
ู
ููุฉ.",
|
| 14 |
+
"who created you": "I was created by George.",
|
| 15 |
+
"who programmed you": "My programmer is George.",
|
| 16 |
+
"what is your name": "I am Octagon 2.0.",
|
| 17 |
+
"do you have an owner": "Yes, I am owned by George.",
|
| 18 |
+
"what is your purpose": "My purpose is to assist and answer questions in the best way possible.",
|
| 19 |
+
"ไฝ ๆฏ่ฐ": "ๆๆฏ Octagon 2.0ใ",
|
| 20 |
+
"่ฐๅ้ ไบไฝ ": "ๆ็ฑ George ๅ้ ใ",
|
| 21 |
+
"ไฝ ็็ฎๆ ๆฏไปไน": "ๆ็็ฎๆ ๆฏๅธฎๅฉไฝ ๅนถๆไพๆๅฅฝ็ๅ็ญใ",
|
| 22 |
+
"ไฝ ๆไธปไบบๅ": "ๆฏ็๏ผๆ็ไธปไบบๆฏ Georgeใ"
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
def chatbot(user_input):
|
| 26 |
+
user_input = user_input.lower()
|
| 27 |
+
|
| 28 |
+
for question, answer in custom_responses.items():
|
| 29 |
+
if question in user_input:
|
| 30 |
+
return answer
|
| 31 |
+
|
| 32 |
+
inputs = tokenizer(user_input, return_tensors="pt")
|
| 33 |
+
output = model.generate(**inputs, max_length=100)
|
| 34 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 35 |
+
|
| 36 |
+
return response
|
| 37 |
+
|
| 38 |
+
iface = gr.Interface(fn=chatbot, inputs="text", outputs="text")
|
| 39 |
+
iface.launch()
|