M17idd commited on
Commit
724300f
·
verified ·
1 Parent(s): 9d9cf53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -28
app.py CHANGED
@@ -1,8 +1,6 @@
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(
@@ -49,21 +47,15 @@ def generate_report(operation_data, max_tokens, temperature, top_p):
49
  HumanMessage(content=f"{system_prompt}\n\n{operation_data}")
50
  ]
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,15 +70,14 @@ demo = gr.Interface(
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,16 +86,16 @@ demo = gr.Interface(
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,25 +103,26 @@ demo = gr.Interface(
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,4 +137,4 @@ demo = gr.Interface(
145
  demo.launch()
146
 
147
  if __name__ == "__main__":
148
- demo.launch()
 
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(
 
47
  HumanMessage(content=f"{system_prompt}\n\n{operation_data}")
48
  ]
49
 
50
+ # ارسال پیام به مدل و گرفتن پاسخ
51
  response = llm(messages)
52
 
53
+ # ذخیره گزارش در یک فایل متنی
54
+ with open("report.txt", "w", encoding="utf-8") as file:
55
+ file.write(response.content)
 
56
 
57
+ return response.content, "report.txt" # لینک به فایل متنی برای دانلود
 
 
 
 
 
58
 
 
59
  demo = gr.Interface(
60
  fn=generate_report,
61
  inputs=[
 
70
  gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="🎯 Top-p", elem_id="slider-3"),
71
  ],
72
  outputs=[
73
+ gr.Textbox(label="📄 گزارش رسمی تولید شده", lines=10, elem_id="military-output")
 
74
  ],
75
  title="🛰️ سامانه گزارش‌ساز هوش مصنوعی «توانا»",
76
  description="🔰 اطلاعات خام عملیات را وارد کن تا سامانه توانا یک گزارش رسمی، حرفه‌ای و محرمانه تولید کند.",
77
  css="""
78
  body {
79
+ background-color: #d9dec5 !important; /* رنگ بک‌گراند جدید */
80
+ color: #1e293b !important; /* رنگ متن جدید */
81
  font-family: 'Vazir', sans-serif;
82
  direction: rtl;
83
  }
 
86
  }
87
  label {
88
  font-size: 22px !important;
89
+ color: #eeeeee !important; /* رنگ سفید برای برچسب‌ها */
90
  font-weight: bold;
91
  }
92
  #military-input textarea, #military-output textarea {
93
  background-color: #d9dec5 !important;
94
  color: #1e293b !important;
95
+ border: 2px solid #529b39 !important; /* رنگ جدید برای مرز */
96
  }
97
  .gr-button {
98
+ background-color: #529b39 !important; /* رنگ دکمه‌ها */
99
  color: #eeeeee !important;
100
  border-radius: 12px;
101
  font-size: 18px;
 
103
  transition: all 0.3s ease;
104
  }
105
  .gr-button:hover {
106
+ background-color: #45a12d !important; /* تغییر رنگ به هنگام hover */
107
  transform: scale(1.05);
108
  }
109
  .gr-button:active {
110
+ background-color: #3b8e27 !important; /* رنگ جدید هنگام کلیک */
111
  }
112
  .gr-button[type="submit"] {
113
+ background-color: #529b39 !important; /* رنگ دکمه "تولید گزارش" */
114
  }
115
  .gr-button[type="reset"] {
116
+ background-color: #ff7043 !important; /* رنگ دکمه "پاک کردن" */
117
  }
118
  .gradio-footer {
119
  display: none !important;
120
  }
121
+
122
  .gr-textbox input[type="text"], .gr-textbox textarea {
123
+ background-color: #1e293b !important; /* رنگ پس‌زمینه ورودی‌ها */
124
+ color: #eeeeee !important; /* رنگ متن ورودی‌ها */
125
+ border: 2px solid #529b39 !important; /* رنگ مرز ورودی‌ها */
126
  font-size: 16px;
127
  }
128
  .gr-textbox input[type="text"]:focus, .gr-textbox textarea:focus {
 
137
  demo.launch()
138
 
139
  if __name__ == "__main__":
140
+ demo.launch()