File size: 1,055 Bytes
59e0faa
b3e3f8a
da16864
7cb60ed
da16864
59e0faa
 
 
 
da16864
59e0faa
 
 
 
 
 
 
d1095eb
59e0faa
 
 
 
 
d1095eb
59e0faa
 
 
 
 
 
 
7cb60ed
b3e3f8a
59e0faa
 
 
b3e3f8a
 
59e0faa
da16864
ec28d0b
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
29
30
31
32
33
34
35
36
37
38
39
40
41
from transformers import MBartForConditionalGeneration, MBart50Tokenizer
import gradio as gr
import train as tr

'''
# Load the model and tokenizer
model_name = "LocalDoc/mbart_large_qa_azerbaijan"
tokenizer = MBart50Tokenizer.from_pretrained(model_name, src_lang="en_XX", tgt_lang="az_AZ")
model = MBartForConditionalGeneration.from_pretrained(model_name)
'''




def answer_question(text, question):
    # Prepare input text
    input_text = f"context: {text} question: {question}"
    inputs = tokenizer(input_text, return_tensors="pt", max_length=1024, truncation=False, padding="max_length")
    
    # Generate answer
    outputs = model.generate(
        input_ids=inputs["input_ids"],
        attention_mask=inputs["attention_mask"],
        max_length=1024,
        num_beams=5,
        early_stopping=True
    )
    
    # Decode the answer
    answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return answer

demo = gr.Interface(
  fn=answer_question,
  inputs=["text", "text"],
  outputs=["text"]
)


#demo.launch()
tr.init()