Spaces:
Sleeping
Sleeping
File size: 3,897 Bytes
1e470c6 c1eaa28 9f2ecc1 0af7025 b74f28e 1e470c6 d51fa15 d3f2071 c1eaa28 d51fa15 b74f28e 1e470c6 b74f28e 1e470c6 aa4a9bc e94f905 ec2e75b 1e1bcae f04358a 74a76fc 9f2ecc1 9d45972 9f2ecc1 d51fa15 b74f28e 0af7025 6475b08 d51fa15 c1eaa28 aa4a9bc 6475b08 d51fa15 0af7025 bf93ff7 11c0800 |
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# 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,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},
# ]
# messages.append(
# {"role": "user", "content": Textbox},
# )
# chat = openai.ChatCompletion.create(
# model="gpt-3.5-turbo", messages=messages
# )
# 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()
from time import sleep
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:
Textbox2 = Textbox2.replace("[", "").replace("]", "").replace("'", "")
Textbox2 = Textbox2.split(",")
Textbox2_edited = [x.strip() for x in Textbox2]
Textbox2_edited = list(Textbox2_edited)
Textbox2_edited.append(Textbox)
messages = [
{"role": "system", "content": content},
]
for i in Textbox2_edited:
messages.append(
{"role": "user", "content": i}
)
try:
sleep(0.8)
chat = openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=messages
)
print(messages)
reply = chat.choices[0].message.content
messages.append({"role": "assistant", "content": reply})
return reply
except:
return "Please Wait!"
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()
|