Spaces:
Runtime error
Runtime error
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() | |