Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
from langchain.chat_models import ChatOpenAI
|
3 |
from langchain.schema import HumanMessage
|
|
|
|
|
4 |
|
5 |
# مدل LLaMA-3 از طریق Together API
|
6 |
llm = ChatOpenAI(
|
@@ -49,11 +51,19 @@ def generate_report(operation_data, max_tokens, temperature, top_p):
|
|
49 |
|
50 |
response = llm(messages)
|
51 |
|
|
|
|
|
|
|
|
|
52 |
|
|
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
|
56 |
|
|
|
57 |
demo = gr.Interface(
|
58 |
fn=generate_report,
|
59 |
inputs=[
|
@@ -68,14 +78,15 @@ demo = gr.Interface(
|
|
68 |
gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="🎯 Top-p", elem_id="slider-3"),
|
69 |
],
|
70 |
outputs=[
|
71 |
-
gr.Textbox(label="📄 گزارش رسمی تولید شده", lines=10, elem_id="military-output")
|
|
|
72 |
],
|
73 |
title="🛰️ سامانه گزارشساز هوش مصنوعی «توانا»",
|
74 |
description="🔰 اطلاعات خام عملیات را وارد کن تا سامانه توانا یک گزارش رسمی، حرفهای و محرمانه تولید کند.",
|
75 |
css="""
|
76 |
body {
|
77 |
-
background-color: #d9dec5 !important;
|
78 |
-
color: #1e293b !important;
|
79 |
font-family: 'Vazir', sans-serif;
|
80 |
direction: rtl;
|
81 |
}
|
@@ -84,16 +95,16 @@ demo = gr.Interface(
|
|
84 |
}
|
85 |
label {
|
86 |
font-size: 22px !important;
|
87 |
-
color: #eeeeee !important;
|
88 |
font-weight: bold;
|
89 |
}
|
90 |
#military-input textarea, #military-output textarea {
|
91 |
background-color: #d9dec5 !important;
|
92 |
color: #1e293b !important;
|
93 |
-
border: 2px solid #529b39 !important;
|
94 |
}
|
95 |
.gr-button {
|
96 |
-
background-color: #529b39 !important;
|
97 |
color: #eeeeee !important;
|
98 |
border-radius: 12px;
|
99 |
font-size: 18px;
|
@@ -101,26 +112,25 @@ demo = gr.Interface(
|
|
101 |
transition: all 0.3s ease;
|
102 |
}
|
103 |
.gr-button:hover {
|
104 |
-
background-color: #45a12d !important;
|
105 |
transform: scale(1.05);
|
106 |
}
|
107 |
.gr-button:active {
|
108 |
-
background-color: #3b8e27 !important;
|
109 |
}
|
110 |
.gr-button[type="submit"] {
|
111 |
-
background-color: #529b39 !important;
|
112 |
}
|
113 |
.gr-button[type="reset"] {
|
114 |
-
background-color: #ff7043 !important;
|
115 |
}
|
116 |
.gradio-footer {
|
117 |
display: none !important;
|
118 |
}
|
119 |
-
|
120 |
.gr-textbox input[type="text"], .gr-textbox textarea {
|
121 |
-
background-color: #1e293b !important;
|
122 |
-
color: #eeeeee !important;
|
123 |
-
border: 2px solid #529b39 !important;
|
124 |
font-size: 16px;
|
125 |
}
|
126 |
.gr-textbox input[type="text"]:focus, .gr-textbox textarea:focus {
|
@@ -135,4 +145,4 @@ demo = gr.Interface(
|
|
135 |
demo.launch()
|
136 |
|
137 |
if __name__ == "__main__":
|
138 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from langchain.chat_models import ChatOpenAI
|
3 |
from langchain.schema import HumanMessage
|
4 |
+
from docx import Document
|
5 |
+
import os
|
6 |
|
7 |
# مدل LLaMA-3 از طریق Together API
|
8 |
llm = ChatOpenAI(
|
|
|
51 |
|
52 |
response = llm(messages)
|
53 |
|
54 |
+
# ذخیره گزارش در فایل ورد
|
55 |
+
doc = Document()
|
56 |
+
doc.add_heading('گزارش رسمی عملیات نظامی', 0)
|
57 |
+
doc.add_paragraph(response.content)
|
58 |
|
59 |
+
# ذخیره فایل ورد
|
60 |
+
file_path = "military_report.docx"
|
61 |
+
doc.save(file_path)
|
62 |
|
63 |
+
# لینک دانلود فایل ورد
|
64 |
+
return response.content, file_path
|
65 |
|
66 |
+
# اینترفیس گراڈیو
|
67 |
demo = gr.Interface(
|
68 |
fn=generate_report,
|
69 |
inputs=[
|
|
|
78 |
gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="🎯 Top-p", elem_id="slider-3"),
|
79 |
],
|
80 |
outputs=[
|
81 |
+
gr.Textbox(label="📄 گزارش رسمی تولید شده", lines=10, elem_id="military-output"),
|
82 |
+
gr.File(label="📝 دانلود گزارش ورد", elem_id="download-link") # نمایش لینک دانلود
|
83 |
],
|
84 |
title="🛰️ سامانه گزارشساز هوش مصنوعی «توانا»",
|
85 |
description="🔰 اطلاعات خام عملیات را وارد کن تا سامانه توانا یک گزارش رسمی، حرفهای و محرمانه تولید کند.",
|
86 |
css="""
|
87 |
body {
|
88 |
+
background-color: #d9dec5 !important;
|
89 |
+
color: #1e293b !important;
|
90 |
font-family: 'Vazir', sans-serif;
|
91 |
direction: rtl;
|
92 |
}
|
|
|
95 |
}
|
96 |
label {
|
97 |
font-size: 22px !important;
|
98 |
+
color: #eeeeee !important;
|
99 |
font-weight: bold;
|
100 |
}
|
101 |
#military-input textarea, #military-output textarea {
|
102 |
background-color: #d9dec5 !important;
|
103 |
color: #1e293b !important;
|
104 |
+
border: 2px solid #529b39 !important;
|
105 |
}
|
106 |
.gr-button {
|
107 |
+
background-color: #529b39 !important;
|
108 |
color: #eeeeee !important;
|
109 |
border-radius: 12px;
|
110 |
font-size: 18px;
|
|
|
112 |
transition: all 0.3s ease;
|
113 |
}
|
114 |
.gr-button:hover {
|
115 |
+
background-color: #45a12d !important;
|
116 |
transform: scale(1.05);
|
117 |
}
|
118 |
.gr-button:active {
|
119 |
+
background-color: #3b8e27 !important;
|
120 |
}
|
121 |
.gr-button[type="submit"] {
|
122 |
+
background-color: #529b39 !important;
|
123 |
}
|
124 |
.gr-button[type="reset"] {
|
125 |
+
background-color: #ff7043 !important;
|
126 |
}
|
127 |
.gradio-footer {
|
128 |
display: none !important;
|
129 |
}
|
|
|
130 |
.gr-textbox input[type="text"], .gr-textbox textarea {
|
131 |
+
background-color: #1e293b !important;
|
132 |
+
color: #eeeeee !important;
|
133 |
+
border: 2px solid #529b39 !important;
|
134 |
font-size: 16px;
|
135 |
}
|
136 |
.gr-textbox input[type="text"]:focus, .gr-textbox textarea:focus {
|
|
|
145 |
demo.launch()
|
146 |
|
147 |
if __name__ == "__main__":
|
148 |
+
demo.launch()
|