ssocean commited on
Commit
222f125
·
verified ·
1 Parent(s): 97b3552

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +112 -11
app.py CHANGED
@@ -12,22 +12,99 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
12
 
13
  model.eval()
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def predict(title, abstract):
16
- # 将标题和摘要处理为一个单一的字符串
17
  text = f'''Given a certain paper, Title: {title}\n Abstract: {abstract}. \n Predict its normalized academic impact (between 0 and 1):'''
18
  inputs = tokenizer(text, return_tensors="pt")
19
  with torch.no_grad():
20
  outputs = model(**inputs.to(device))
21
- # 应用 Sigmoid 函数来获取概率输出
22
  probability = torch.sigmoid(outputs.logits).item()
23
- return {"Predicted Impact": round(probability, 4)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  # 创建 Gradio 界面
26
  with gr.Blocks() as iface:
27
  gr.Markdown("""
28
- # 🧠 Predict Academic Impact of newly published paper!!
29
- ### Estimate the future academic impact of a paper using AI
30
- ---
31
  [Read the full paper](https://arxiv.org/abs/2408.03934)
32
  """)
33
  with gr.Row():
@@ -42,21 +119,45 @@ with gr.Blocks() as iface:
42
  placeholder="Enter Paper Abstract Here... (Do not input line breaks. No more than 1024 tokens.)",
43
  label="Paper Abstract"
44
  )
45
- submit_button = gr.Button("Predict Impact")
 
46
  with gr.Column():
47
  output = gr.Label(label="Predicted Impact")
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  gr.Markdown("""
50
  **Important Notes**
51
  - It is intended as a tool for research and educational purposes only.
52
- - The web version is a demo for testing purposes. Due to partial environment discrepancies, predictions may have a deviation of up to <0.05.
53
  - Predicted impact is a probabilistic value generated by the model and does not reflect paper quality or novelty.
54
  - The author takes no responsibility for the prediction results.
55
  - To identify potentially impactful papers, this study uses the sigmoid+MSE approach to optimize NDCG values (over sigmoid+BCE), resulting in predicted values concentrated between 0.1 and 0.9 due to the sigmoid gradient effect.
56
- - Generally, we consider a predicted influence score greater than 0.65 to indicate an exceptionally impactful paper.
57
  """)
58
- submit_button.click(predict, inputs=[title_input, abstract_input], outputs=output)
59
-
60
  iface.launch()
61
 
62
 
 
 
 
12
 
13
  model.eval()
14
 
15
+ def validate_input(title, abstract):
16
+ """验证输入是否符合要求"""
17
+
18
+ # 黑名单:屏蔽非拉丁字符
19
+ non_latin_pattern = re.compile(r'[^\u0000-\u007F]')
20
+ if len(title.split(' '))<4:
21
+ return False, "The title must be at least 3 words long."
22
+ if len(abstract.split(' ')) < 50:
23
+ return False, "The abstract must be at least 50 words long."
24
+ if len((title + abstract).split(' '))>1024:
25
+ return True, "Warning, The input length is approaching tokenization limits (1024) and may be truncated without further warning!"
26
+ if non_latin_pattern.search(title):
27
+ return False, "The title contains invalid characters. Only English letters and special symbols are allowed."
28
+ if non_latin_pattern.search(abstract):
29
+ return False, "The abstract contains invalid characters. Only English letters and special symbols are allowed."
30
+
31
+ return True, "Inputs are valid! Good to go!"
32
+
33
+ def update_button_status(title, abstract):
34
+ """根据输入内容动态更新按钮状态"""
35
+ valid, message = validate_input(title, abstract)
36
+ if not valid:
37
+ return gr.update(value="Error: " + message), gr.update(interactive=False)
38
+ return gr.update(value=message), gr.update(interactive=True)
39
+
40
+
41
  def predict(title, abstract):
 
42
  text = f'''Given a certain paper, Title: {title}\n Abstract: {abstract}. \n Predict its normalized academic impact (between 0 and 1):'''
43
  inputs = tokenizer(text, return_tensors="pt")
44
  with torch.no_grad():
45
  outputs = model(**inputs.to(device))
 
46
  probability = torch.sigmoid(outputs.logits).item()
47
+ # reason for +0.05: We observed that the predicted values in the web demo are generally around 0.05 lower than those in the local deployment (due to differences in software/hardware environments). Therefore, we applied the following compensation in the web demo. Please do not use this in the local deployment.
48
+ return round(probability + 0.05, 4)
49
+
50
+
51
+ # 示例数据
52
+ examples = [
53
+ [
54
+ "LoRA-IR: Taming Low-Rank Experts for Efficient All-in-One Image Restoration",
55
+ ('''Prompt-based all-in-one image restoration (IR) frameworks have achieved
56
+ remarkable performance by incorporating degradation-specific information into
57
+ prompt modules. Nevertheless, handling the complex and diverse degradations
58
+ encountered in real-world scenarios remains a significant challenge. To address
59
+ this challenge, we propose LoRA-IR, a flexible framework that dynamically
60
+ leverages compact low-rank experts to facilitate efficient all-in-one image
61
+ restoration. Specifically, LoRA-IR consists of two training stages:
62
+ degradation-guided pre-training and parameter-efficient fine-tuning. In the
63
+ pre-training stage, we enhance the pre-trained CLIP model by introducing a
64
+ simple mechanism that scales it to higher resolutions, allowing us to extract
65
+ robust degradation representations that adaptively guide the IR network. In the
66
+ fine-tuning stage, we refine the pre-trained IR network using low-rank
67
+ adaptation (LoRA). Built upon a Mixture-of-Experts (MoE) architecture, LoRA-IR
68
+ dynamically integrates multiple low-rank restoration experts through a
69
+ degradation-guided router. This dynamic integration mechanism significantly
70
+ enhances our model's adaptability to diverse and unknown degradations in
71
+ complex real-world scenarios. Extensive experiments demonstrate that LoRA-IR
72
+ achieves state-of-the-art performance across 14 image restoration tasks and 29
73
+ benchmarks. Code and pre-trained models will be available at:
74
+ https://github.com/shallowdream204/LoRA-IR.''')
75
+ ],
76
+ [
77
+ "ConsistentAvatar: Learning to Diffuse Fully Consistent Talking Head Avatar with Temporal Guidance",
78
+ ('''Diffusion models have shown impressive potential on talking head generation.
79
+ While plausible appearance and talking effect are achieved, these methods still
80
+ suffer from temporal, 3D or expression inconsistency due to the error
81
+ accumulation and inherent limitation of single-image generation ability. In
82
+ this paper, we propose ConsistentAvatar, a novel framework for fully consistent
83
+ and high-fidelity talking avatar generation. Instead of directly employing
84
+ multi-modal conditions to the diffusion process, our method learns to first
85
+ model the temporal representation for stability between adjacent frames.
86
+ Specifically, we propose a Temporally-Sensitive Detail (TSD) map containing
87
+ high-frequency feature and contours that vary significantly along the time
88
+ axis. Using a temporal consistent diffusion module, we learn to align TSD of
89
+ the initial result to that of the video frame ground truth. The final avatar is
90
+ generated by a fully consistent diffusion module, conditioned on the aligned
91
+ TSD, rough head normal, and emotion prompt embedding. We find that the aligned
92
+ TSD, which represents the temporal patterns, constrains the diffusion process
93
+ to generate temporally stable talking head. Further, its reliable guidance
94
+ complements the inaccuracy of other conditions, suppressing the accumulated
95
+ error while improving the consistency on various aspects. Extensive experiments
96
+ demonstrate that ConsistentAvatar outperforms the state-of-the-art methods on
97
+ the generated appearance, 3D, expression and temporal consistency. Project
98
+ page: https://njust-yang.github.io/ConsistentAvatar.github.io/''')
99
+ ],
100
+
101
+ ]
102
 
103
  # 创建 Gradio 界面
104
  with gr.Blocks() as iface:
105
  gr.Markdown("""
106
+ # 🧠 Predict Academic Impact of Newly Published Paper!
107
+ ### Estimate the future academic impact of a paper using LLM
 
108
  [Read the full paper](https://arxiv.org/abs/2408.03934)
109
  """)
110
  with gr.Row():
 
119
  placeholder="Enter Paper Abstract Here... (Do not input line breaks. No more than 1024 tokens.)",
120
  label="Paper Abstract"
121
  )
122
+ validation_status = gr.Textbox(label="Validation Status", interactive=False)
123
+ submit_button = gr.Button("Predict Impact", interactive=False)
124
  with gr.Column():
125
  output = gr.Label(label="Predicted Impact")
126
 
127
+ # 输入事件绑定
128
+ title_input.change(
129
+ update_button_status,
130
+ inputs=[title_input, abstract_input],
131
+ outputs=[validation_status, submit_button]
132
+ )
133
+ abstract_input.change(
134
+ update_button_status,
135
+ inputs=[title_input, abstract_input],
136
+ outputs=[validation_status, submit_button]
137
+ )
138
+
139
+ submit_button.click(
140
+ predict,
141
+ inputs=[title_input, abstract_input],
142
+ outputs=output
143
+ )
144
+
145
+ gr.Examples(
146
+ examples=examples,
147
+ inputs=[title_input, abstract_input],
148
+ outputs=[validation_status, output],
149
+ cache_examples=False
150
+ )
151
  gr.Markdown("""
152
  **Important Notes**
153
  - It is intended as a tool for research and educational purposes only.
 
154
  - Predicted impact is a probabilistic value generated by the model and does not reflect paper quality or novelty.
155
  - The author takes no responsibility for the prediction results.
156
  - To identify potentially impactful papers, this study uses the sigmoid+MSE approach to optimize NDCG values (over sigmoid+BCE), resulting in predicted values concentrated between 0.1 and 0.9 due to the sigmoid gradient effect.
157
+ - Generally, it is considered a predicted influence score greater than 0.65 to indicate an exceptionally impactful paper.
158
  """)
 
 
159
  iface.launch()
160
 
161
 
162
+
163
+