File size: 1,367 Bytes
896ef55
ad87178
896ef55
22f3116
896ef55
ad87178
 
 
 
 
896ef55
 
ad87178
 
 
 
c86406f
 
ad87178
c86406f
 
ad87178
 
 
896ef55
c86406f
ad87178
 
896ef55
 
 
ad87178
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
from huggingface_hub import InferenceClient
import gradio as gr

client = InferenceClient("HooshvareLab/gpt2-fa")

def generate_report_farsi(prompt, max_tokens, temperature, top_p):
    full_prompt = f"گزارش رسمی عملیات نظامی بر اساس اطلاعات زیر تهیه کن:\n{prompt}\nگزارش:"
    output = client.text_generation(
        prompt=full_prompt,
        max_new_tokens=max_tokens,
        temperature=temperature,
        top_p=top_p,
        do_sample=True,
        repetition_penalty=1.1
    )
    return output

demo = gr.Interface(
    fn=generate_report_farsi,
    inputs=[
        gr.Textbox(label="اطلاعات عملیات نظامی", lines=10, placeholder="مثلاً: در ساعت ۵ صبح، گردان الف از محور غربی وارد منطقه شد..."),
        gr.Slider(1, 512, value=200, label="حداکثر توکن خروجی"),
        gr.Slider(0.1, 2.0, value=0.9, step=0.1, label="دمای خلاقیت (temperature)"),
        gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p"),
    ],
    outputs=gr.Textbox(label="گزارش رسمی تولید شده"),
    title="گزارش‌نویس فارسی عملیات نظامی",
    description="اطلاعات عملیات را وارد کن تا گزارش فارسی تولید شود."
)

if __name__ == "__main__":
    demo.launch()