File size: 1,645 Bytes
896ef55
 
 
896f90e
896ef55
c86406f
 
896ef55
c86406f
 
 
 
896ef55
c86406f
896ef55
 
 
 
 
 
 
 
 
c86406f
 
 
 
 
 
 
 
 
 
896ef55
c86406f
 
 
896ef55
 
 
 
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
42
import gradio as gr
from huggingface_hub import InferenceClient

client = InferenceClient("OpenChat/openchat-3.5-0106")

def generate_report(operation_data, max_tokens, temperature, top_p):
    system_prompt = "تو یک افسر گزارش‌نویس نظامی هستی. از داده‌های خام عملیات نظامی، یک گزارش رسمی، دقیق و خلاصه تهیه کن."

    messages = [
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": operation_data}
    ]

    report = ""

    for message in client.chat_completion(
        messages,
        max_tokens=max_tokens,
        stream=True,
        temperature=temperature,
        top_p=top_p,
    ):
        token = message.choices[0].delta.content
        report += token
        yield report

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

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