Spaces:
Sleeping
Sleeping
File size: 2,168 Bytes
4e3c65a 88ad7d5 fa6c86b d670775 fa6c86b d670775 88ad7d5 d670775 fa6c86b d670775 88ad7d5 d670775 88ad7d5 fa6c86b d670775 fa6c86b d670775 88ad7d5 d670775 4e3c65a 1d582a7 fa6c86b d670775 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import gradio as gr
from openai import OpenAI
import json
import os
env_key = os.environ.get("api_key")
base_url = os.environ.get("mistrial_api")
client = OpenAI(
api_key=env_key,
base_url=base_url
)
def test_api():
models = client.models.list()
return str(models.model_dump())
def generate(user_prompt,system_prompt, temperature, top_p,api_key):
if api_key != env_key:
return {
"error": "Invalid API key"
}
chat_completion = client.chat.completions.create(
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt},
],
seed=42,
model="mistral",
n=3,
temperature=temperature,
top_p=top_p,
)
return json.loads(chat_completion.choices[0].message.content)
def review_paper(paper_abstract, temperature, top_p,api_key):
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 ...?']}"
user_prompt = "###Paper abstract:\n" + paper_abstract
result = generate(user_prompt, system_prompt, temperature, top_p,api_key)
return json.dumps(result, indent=4, ensure_ascii=False)
iface = gr.Interface(fn=review_paper, inputs=["text", gr.Slider(0.0, 1.0), gr.Slider(0.0, 1.0), "text"],
outputs="text", title="Review Paper", description="This is a tool to help you review a paper.")
iface.launch()
|