File size: 1,059 Bytes
aea6f00
 
7cc244b
aea6f00
 
 
7cc244b
aea6f00
 
 
 
 
 
7cc244b
aea6f00
 
 
 
 
 
 
 
 
 
7cc244b
 
aea6f00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr
from transformers import MT5ForConditionalGeneration, MT5Tokenizer

# Модельді жүктеу
model = MT5ForConditionalGeneration.from_pretrained("model")
tokenizer = MT5Tokenizer.from_pretrained("google/mt5-small")

# Сұраққа жауап беру функциясы
def answer_question(question, context):
    input_text = f"Сұрақ: {question} Контекст: {context}"
    input_ids = tokenizer(input_text, return_tensors="pt").input_ids
    output_ids = model.generate(input_ids, max_length=128)
    return tokenizer.decode(output_ids[0], skip_special_tokens=True)

# Интерфейс
iface = gr.Interface(
    fn=answer_question,
    inputs=[
        gr.Textbox(label="Сұрақ жазыңыз"),
        gr.Textbox(label="Контекст (мәтін үзіндісі)")
    ],
    outputs="text",
    title="Қазақша AI-ассистент",
    description="Сұрақ қойып, контекст бойынша жауап алыңыз (Мәліметтер қоры тақырыбы)"
)

iface.launch()