File size: 1,226 Bytes
80132d7
520907f
 
80132d7
520907f
 
 
80132d7
520907f
fa27525
520907f
 
 
fa27525
80132d7
520907f
 
80132d7
 
520907f
80132d7
fa27525
 
 
520907f
 
80132d7
 
520907f
 
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
import gradio as gr
from transformers import T5Tokenizer, T5ForConditionalGeneration
import torch

# Load the fine-tuned summarisation model
model = T5ForConditionalGeneration.from_pretrained("drelhaj/FinAraT5")
tokenizer = T5Tokenizer.from_pretrained("drelhaj/FinAraT5")  # Assumes spiece.model is present on the Hub

# Define summarisation logic
def summarise(text):
    text = text.strip()
    if not text.startswith("لخص:"):
        text = "لخص: " + text

    inputs = tokenizer(text, return_tensors="pt", truncation=True)
    with torch.no_grad():
        outputs = model.generate(**inputs, max_length=64)
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

# Gradio interface
demo = gr.Interface(
    fn=summarise,
    inputs=gr.Textbox(lines=4, placeholder="أدخل نصًا ماليًا باللغة العربية..."),
    outputs="text",
    title="FinAraT5 – Arabic Financial News Summarisation",
    description="يستخدم هذا النموذج لإنشاء ملخصات قصيرة للأخبار المالية العربية. إذا لم يبدأ الإدخال بـ 'لخص:' فسيتم إضافته تلقائيًا."
)

# Launch the app
demo.launch()