Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
|
| 4 |
-
|
| 5 |
-
model = MT5ForConditionalGeneration.from_pretrained("model")
|
| 6 |
-
tokenizer = MT5Tokenizer.from_pretrained("google/mt5-small")
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|