Spaces:
Sleeping
Sleeping
Commit
·
d670775
1
Parent(s):
28fa6fa
Upload app.py
Browse files
app.py
CHANGED
@@ -3,22 +3,52 @@ from openai import OpenAI
|
|
3 |
import json
|
4 |
import os
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def test_api():
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
)
|
|
|
13 |
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
# List models API
|
16 |
-
models = client.models.list()
|
17 |
-
return str(models.model_dump())
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
def greet(name):
|
21 |
-
return "Hello " + name + "!!" + test_api()
|
22 |
|
23 |
-
iface = gr.Interface(fn=
|
24 |
-
iface.launch()
|
|
|
3 |
import json
|
4 |
import os
|
5 |
|
6 |
+
api_key = os.environ.get("api_key")
|
7 |
+
base_url = os.environ.get("mistrial_api")
|
8 |
+
client = OpenAI(
|
9 |
+
api_key=api_key,
|
10 |
+
base_url=base_url
|
11 |
+
)
|
12 |
+
|
13 |
def test_api():
|
14 |
+
models = client.models.list()
|
15 |
+
return str(models.model_dump())
|
16 |
+
|
17 |
+
|
18 |
+
def generate(user_prompt,system_prompt, temperature, top_p):
|
19 |
+
chat_completion = client.chat.completions.create(
|
20 |
+
messages=[
|
21 |
+
{"role": "system", "content": system_prompt},
|
22 |
+
{"role": "user", "content": user_prompt},
|
23 |
+
],
|
24 |
+
seed=42,
|
25 |
+
model="mistral",
|
26 |
+
n=3,
|
27 |
+
temperature=temperature,
|
28 |
+
top_p=top_p,
|
29 |
)
|
30 |
+
return json.loads(chat_completion.choices[0].message.content)
|
31 |
|
32 |
+
def review_paper(paper_abstract, temperature, top_p):
|
33 |
+
system_prompt = "###System prompt:\nYou are a helpful, professional reviewer. You are reviewing a scientific paper. You should provide at least 2 contribution bullets. You should provide at least 2 strengths and 2 weaknesses of the paper. You should provide at least 2 suggestions to improve the paper. You should provide at least 3 questions to the authors.\n###OutputFomrat:\nYou should return your answer in JSON format. For example, {'contribution': ['This paper proposes a new method for ...', 'This paper proposes a new method for ...'], 'strengths': ['The paper is well written.', 'The paper is well written.'], 'weaknesses': ['The paper is not well written.', 'The paper is not well written.'], 'suggestions': ['The authors should ...', 'The authors should ...'], 'questions': ['Why do you ...?', 'Why do you ...?']}"
|
34 |
+
user_prompt = "###Paper abstract:\n" + paper_abstract
|
35 |
+
result = generate(user_prompt, system_prompt, temperature, top_p)
|
36 |
+
return json.dumps(result, indent=4, ensure_ascii=False)
|
37 |
|
|
|
|
|
|
|
38 |
|
39 |
+
# 界面
|
40 |
+
with gr.Blocks("Paper Abstract"):
|
41 |
+
paper_abstract = gr.inputs.Textbox(lines=10, label="Paper Abstract")
|
42 |
+
with gr.Blocks("Temperature"):
|
43 |
+
temperature = gr.inputs.Slider(minimum=0, maximum=1, default=0.5, label="Temperature")
|
44 |
+
with gr.Blocks("Top P"):
|
45 |
+
top_p = gr.inputs.Slider(minimum=0, maximum=1, default=0.9, label="Top P")
|
46 |
+
|
47 |
+
# 结果展示
|
48 |
+
|
49 |
+
with gr.Blocks("Output"):
|
50 |
+
gr.outputs.Textbox(label="Output")
|
51 |
|
|
|
|
|
52 |
|
53 |
+
iface = gr.Interface(fn=review_paper, inputs=[paper_abstract, temperature, top_p], outputs="text", title="Review Paper", description="This is a tool to help you review a paper.")
|
54 |
+
iface.launch()
|