Nurisslam commited on
Commit
eb02560
·
verified ·
1 Parent(s): f5ea7e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -23
app.py CHANGED
@@ -1,27 +1,11 @@
1
  import gradio as gr
2
- from transformers import MT5ForConditionalGeneration, MT5Tokenizer
3
 
4
- # Модельді жүктеу
5
- model = MT5ForConditionalGeneration.from_pretrained("model")
6
- tokenizer = MT5Tokenizer.from_pretrained("google/mt5-small")
7
 
8
- # Сұраққа жауап беру функциясы
9
- def answer_question(question, context):
10
- input_text = f"Сұрақ: {question} Контекст: {context}"
11
- input_ids = tokenizer(input_text, return_tensors="pt").input_ids
12
- output_ids = model.generate(input_ids, max_length=128)
13
- return tokenizer.decode(output_ids[0], skip_special_tokens=True)
14
 
15
- # Интерфейс
16
- iface = gr.Interface(
17
- fn=answer_question,
18
- inputs=[
19
- gr.Textbox(label="Сұрақ жазыңыз"),
20
- gr.Textbox(label="Контекст (мәтін үзіндісі)")
21
- ],
22
- outputs="text",
23
- title="Қазақша AI-ассистент",
24
- description="Сұрақ қойып, контекст бойынша жауап алыңыз (Мәліметтер қоры тақырыбы)"
25
- )
26
-
27
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ qa_pipeline = pipeline("question-answering", model="./model", tokenizer="./model")
 
 
5
 
6
+ def answer_question(question):
7
+ context = open("data.txt", encoding="utf-8").read()
8
+ result = qa_pipeline(question=question, context=context)
9
+ return result["answer"]
 
 
10
 
11
+ gr.Interface(fn=answer_question, inputs="text", outputs="text", title="Қазақша Ассистент").launch()