Spaces:
Sleeping
Sleeping
# import gradio as gr | |
# import requests | |
# import os | |
# def function(Textbox,Textbox2): | |
# target = os.environ.get("target") | |
# target2 = os.environ.get("target2") | |
# model = os.environ.get("model") | |
# hrc = os.environ.get("hrc") | |
# content = os.environ.get("content") | |
# if Textbox2 == target: | |
# payload = { | |
# "model": "gpt-3.5-turbo", | |
# "messages": [{"role": "system", "content": content},{"role": "user", "content": Textbox}], | |
# "temperature" : 1.0, | |
# "top_p":1.0, | |
# "n" : 1, | |
# "stream": False, | |
# "presence_penalty":0, | |
# "frequency_penalty":0, | |
# } | |
# headers = { | |
# "Content-Type": "application/json", | |
# "Authorization": f"Bearer {target2}" | |
# } | |
# response = requests.post(hrc, headers=headers, json=payload, stream=False) | |
# response = response.json() | |
# return response["choices"][0]["message"]["content"] | |
# else: | |
# return "Failed" | |
# inputs = [ | |
# gr.inputs.Textbox(label="Textbox",type="text"), | |
# gr.inputs.Textbox(label="Textbox2",type="password") | |
# ] | |
# iface = gr.Interface(fn=function, inputs=inputs, outputs="text") | |
# iface.launch() | |
import gradio as gr | |
import requests | |
import openai | |
import os | |
def function(Textbox,Textbox2,Textbox3): | |
target = os.environ.get("target") | |
target2 = os.environ.get("target2") | |
openai.api_key = target2 | |
content = os.environ.get("content") | |
# model = os.environ.get("model") | |
# hrc = os.environ.get("hrc") | |
if Textbox3 == target: | |
# messages = [ | |
# {"role": "system", "content": content}, | |
# ] | |
if Textbox2: | |
chat = openai.ChatCompletion.create( | |
model="gpt-3.5-turbo", messages=Textbox2 | |
) | |
reply = chat.choices[0].message.content | |
messages.append({"role": "assistant", "content": reply}) | |
return reply | |
else: | |
return "Failed" | |
inputs = [ | |
gr.inputs.Textbox(label="Textbox",type="text"), | |
gr.inputs.Textbox(label="Textbox2",type="text"), | |
gr.inputs.Textbox(label="Textbox3",type="password") | |
] | |
iface = gr.Interface(fn=function, inputs=inputs, outputs="text") | |
iface.launch() | |