Spaces:
Sleeping
Sleeping
Commit
·
fa6c86b
1
Parent(s):
d670775
Upload app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,10 @@ from openai import OpenAI
|
|
3 |
import json
|
4 |
import os
|
5 |
|
6 |
-
|
7 |
base_url = os.environ.get("mistrial_api")
|
8 |
client = OpenAI(
|
9 |
-
api_key=
|
10 |
base_url=base_url
|
11 |
)
|
12 |
|
@@ -15,7 +15,11 @@ def test_api():
|
|
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},
|
@@ -29,26 +33,16 @@ def generate(user_prompt,system_prompt, temperature, 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 |
-
|
54 |
iface.launch()
|
|
|
3 |
import json
|
4 |
import os
|
5 |
|
6 |
+
env_key = os.environ.get("api_key")
|
7 |
base_url = os.environ.get("mistrial_api")
|
8 |
client = OpenAI(
|
9 |
+
api_key=env_key,
|
10 |
base_url=base_url
|
11 |
)
|
12 |
|
|
|
15 |
return str(models.model_dump())
|
16 |
|
17 |
|
18 |
+
def generate(user_prompt,system_prompt, temperature, top_p,api_key):
|
19 |
+
if api_key != env_key:
|
20 |
+
return {
|
21 |
+
"error": "Invalid API key"
|
22 |
+
}
|
23 |
chat_completion = client.chat.completions.create(
|
24 |
messages=[
|
25 |
{"role": "system", "content": system_prompt},
|
|
|
33 |
)
|
34 |
return json.loads(chat_completion.choices[0].message.content)
|
35 |
|
36 |
+
def review_paper(paper_abstract, temperature, top_p,api_key):
|
37 |
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 ...?']}"
|
38 |
user_prompt = "###Paper abstract:\n" + paper_abstract
|
39 |
+
result = generate(user_prompt, system_prompt, temperature, top_p,api_key)
|
40 |
return json.dumps(result, indent=4, ensure_ascii=False)
|
41 |
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
|
|
44 |
|
|
|
|
|
45 |
|
46 |
+
iface = gr.Interface(fn=review_paper, inputs=["text", gr.inputs.Slider(0.0, 1.0), gr.inputs.Slider(0.0, 1.0), "text"],
|
47 |
+
outputs="text", title="Review Paper", description="This is a tool to help you review a paper.")
|
48 |
iface.launch()
|