Spaces:
Sleeping
Sleeping
File size: 2,277 Bytes
1e470c6 0af7025 b74f28e 1e470c6 d51fa15 d3f2071 aa4a9bc d51fa15 b74f28e 1e470c6 b74f28e 1e470c6 aa4a9bc 1e470c6 d51fa15 b74f28e 0af7025 6475b08 d51fa15 aa4a9bc 6475b08 d51fa15 0af7025 bf93ff7 |
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# 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()
|