ddfws commited on
Commit
d48d1c6
·
verified ·
1 Parent(s): 0d6d035

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -29
app.py CHANGED
@@ -29,39 +29,33 @@ print("MODEL READY")
29
 
30
 
31
 
32
- @spaces.GPU
33
- def generate(message, history):
34
 
35
- prompt = """
36
- You are Rezaeian StatsAI.
37
- You are a professional statistics assistant.
38
 
39
- Rules:
40
- - Answer in Persian when user writes Persian.
41
- - Write statistical formulas clearly.
42
- - Keep numbers and English letters separated correctly.
43
- - Use readable mathematical notation.
44
- """
 
45
 
46
 
47
- for user, assistant in history:
48
- prompt += f"""
49
 
50
- User:
51
- {user}
52
 
53
- Assistant:
54
- {assistant}
55
- """
56
 
57
 
58
- prompt += f"""
59
 
60
- User:
61
- {message}
62
 
63
- Assistant:
64
- """
65
 
66
 
67
  inputs = tokenizer(
@@ -71,8 +65,8 @@ Assistant:
71
 
72
 
73
  inputs = {
74
- k:v.to(model.device)
75
- for k,v in inputs.items()
76
  }
77
 
78
 
@@ -95,14 +89,15 @@ Assistant:
95
 
96
  answer = result.split("Assistant:")[-1]
97
 
98
- return answer
 
99
 
100
 
101
 
102
  demo = gr.ChatInterface(
103
  fn=generate,
104
  title="Rezaeian StatsAI",
105
- description="دستیار هوشمند آمار و احتمال مهندسی"
106
  )
107
 
108
 
@@ -116,18 +111,33 @@ demo.launch(
116
  max-width: 1200px !important;
117
  }
118
 
119
- textarea {
 
120
  direction: rtl !important;
121
  text-align: right !important;
 
122
  font-size:18px !important;
 
123
  }
124
 
125
- .message {
 
126
  direction: rtl !important;
127
  text-align:right !important;
128
  font-size:18px !important;
129
  }
130
 
 
 
 
 
 
 
 
 
 
 
 
131
  footer {
132
  display:none !important;
133
  }
 
29
 
30
 
31
 
32
+ def format_answer(text):
 
33
 
34
+ # مرتب سازی خروجی فارسی
35
+ text = text.replace("\n", "<br>")
 
36
 
37
+ # فرمول های LaTeX
38
+ text = text.replace("\\[", "<div class='formula'>")
39
+ text = text.replace("\\]", "</div>")
40
+
41
+ text = text.replace("$$", "<div class='formula'>")
42
+
43
+ return text
44
 
45
 
 
 
46
 
47
+ @spaces.GPU
48
+ def generate(message, history):
49
 
50
+ prompt = ""
 
 
51
 
52
 
53
+ for user, assistant in history:
54
 
55
+ prompt += f"User: {user}\nAssistant: {assistant}\n"
 
56
 
57
+
58
+ prompt += f"User: {message}\nAssistant:"
59
 
60
 
61
  inputs = tokenizer(
 
65
 
66
 
67
  inputs = {
68
+ k: v.to(model.device)
69
+ for k, v in inputs.items()
70
  }
71
 
72
 
 
89
 
90
  answer = result.split("Assistant:")[-1]
91
 
92
+
93
+ return format_answer(answer)
94
 
95
 
96
 
97
  demo = gr.ChatInterface(
98
  fn=generate,
99
  title="Rezaeian StatsAI",
100
+ description="دستیار هوشمند آمار و فرمول‌های آماری"
101
  )
102
 
103
 
 
111
  max-width: 1200px !important;
112
  }
113
 
114
+
115
+ .message {
116
  direction: rtl !important;
117
  text-align: right !important;
118
+ font-family: Tahoma, Arial, sans-serif !important;
119
  font-size:18px !important;
120
+ line-height:2;
121
  }
122
 
123
+
124
+ textarea {
125
  direction: rtl !important;
126
  text-align:right !important;
127
  font-size:18px !important;
128
  }
129
 
130
+
131
+ .formula {
132
+ direction:ltr !important;
133
+ text-align:center !important;
134
+ font-family: Cambria Math, Times New Roman, serif !important;
135
+ font-size:20px !important;
136
+ padding:12px;
137
+ margin:12px;
138
+ }
139
+
140
+
141
  footer {
142
  display:none !important;
143
  }