Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
import os
|
4 |
|
5 |
def function(Textbox,Textbox2):
|
6 |
target = os.environ.get("target")
|
7 |
target2 = os.environ.get("target2")
|
8 |
-
|
9 |
-
hrc = os.environ.get("hrc")
|
10 |
content = os.environ.get("content")
|
|
|
|
|
11 |
if Textbox2 == target:
|
12 |
-
|
13 |
-
"
|
14 |
-
|
15 |
-
|
16 |
-
"
|
17 |
-
|
18 |
-
|
19 |
-
"
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
"Content-Type": "application/json",
|
25 |
-
"Authorization": f"Bearer {target2}"
|
26 |
-
}
|
27 |
-
|
28 |
-
response = requests.post(hrc, headers=headers, json=payload, stream=False)
|
29 |
-
response = response.json()
|
30 |
-
return response["choices"][0]["message"]["content"]
|
31 |
else:
|
32 |
return "Failed"
|
33 |
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
# import requests
|
3 |
+
# import os
|
4 |
+
|
5 |
+
# def function(Textbox,Textbox2):
|
6 |
+
# target = os.environ.get("target")
|
7 |
+
# target2 = os.environ.get("target2")
|
8 |
+
# model = os.environ.get("model")
|
9 |
+
# hrc = os.environ.get("hrc")
|
10 |
+
# content = os.environ.get("content")
|
11 |
+
# if Textbox2 == target:
|
12 |
+
# payload = {
|
13 |
+
# "model": "gpt-3.5-turbo",
|
14 |
+
# "messages": [{"role": "system", "content": content},{"role": "user", "content": Textbox}],
|
15 |
+
# "temperature" : 1.0,
|
16 |
+
# "top_p":1.0,
|
17 |
+
# "n" : 1,
|
18 |
+
# "stream": False,
|
19 |
+
# "presence_penalty":0,
|
20 |
+
# "frequency_penalty":0,
|
21 |
+
# }
|
22 |
+
|
23 |
+
# headers = {
|
24 |
+
# "Content-Type": "application/json",
|
25 |
+
# "Authorization": f"Bearer {target2}"
|
26 |
+
# }
|
27 |
+
|
28 |
+
# response = requests.post(hrc, headers=headers, json=payload, stream=False)
|
29 |
+
# response = response.json()
|
30 |
+
# return response["choices"][0]["message"]["content"]
|
31 |
+
# else:
|
32 |
+
# return "Failed"
|
33 |
+
|
34 |
+
# inputs = [
|
35 |
+
# gr.inputs.Textbox(label="Textbox",type="text"),
|
36 |
+
# gr.inputs.Textbox(label="Textbox2",type="password")
|
37 |
+
# ]
|
38 |
+
|
39 |
+
# iface = gr.Interface(fn=function, inputs=inputs, outputs="text")
|
40 |
+
|
41 |
+
# iface.launch()
|
42 |
+
|
43 |
import gradio as gr
|
44 |
import requests
|
45 |
+
import openai
|
46 |
import os
|
47 |
|
48 |
def function(Textbox,Textbox2):
|
49 |
target = os.environ.get("target")
|
50 |
target2 = os.environ.get("target2")
|
51 |
+
openai.api_key = target2
|
|
|
52 |
content = os.environ.get("content")
|
53 |
+
# model = os.environ.get("model")
|
54 |
+
# hrc = os.environ.get("hrc")
|
55 |
if Textbox2 == target:
|
56 |
+
messages = [
|
57 |
+
{"role": "system", "content": content},
|
58 |
+
]
|
59 |
+
messages.append(
|
60 |
+
{"role": "user", "content": Textbox},
|
61 |
+
)
|
62 |
+
chat = openai.ChatCompletion.create(
|
63 |
+
model="gpt-3.5-turbo", messages=messages
|
64 |
+
)
|
65 |
+
reply = chat.choices[0].message.content
|
66 |
+
messages.append({"role": "assistant", "content": reply})
|
67 |
+
return reply
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
else:
|
69 |
return "Failed"
|
70 |
|