import gradio as gr from scholarly import scholarly, ProxyGenerator import openai def process(key, choice, artitle, trans): openai.api_key = str(key) results = [] if choice=='单个生成': pg = ProxyGenerator() pg.FreeProxies() scholarly.use_proxy(pg) search_query = scholarly.search_pubs(str(artitle)) pub = next(search_query) bib = scholarly.bibtex(pub) if trans=='bib': results.append(bib) else: prompt = "请把以下bib格式转为"+str(trans)+"格式:"+str(bib) completion = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt} ] ) print(completion.choices[0].message['content']) print(completion.choices[0].text) results.append(completion.choices[0].message) if choice=='批量生成': m_artitle = artitle.split('\n') for i in range(len(m_artitle)): if trans=='bib': results.append(bib) else: pg = ProxyGenerator() pg.FreeProxies() scholarly.use_proxy(pg) search_query = scholarly.search_pubs(str(m_artitle[i])) pub = next(search_query) bib = scholarly.bibtex(pub) prompt = "请把以下bib格式转为"+str(trans)+"格式:"+str(bib) completion = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt} ] ) results.append(completion.choices[0].message+'\n') return results # 标题 title = "ChatCitation" # 描述 description = '''