Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
| 2 |
|
|
|
|
| 3 |
os.system("pip install transformers")
|
| 4 |
os.system("pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117")
|
| 5 |
|
| 6 |
-
|
| 7 |
-
import openai
|
| 8 |
-
import gradio as gr
|
| 9 |
-
|
| 10 |
openai.api_key = "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"
|
| 11 |
|
|
|
|
| 12 |
messages = [
|
| 13 |
{"role": "system", "content": "You are an AI assistant who can answer any question. You are an AI assistant who can answer almost any question. When answering a question, you must respond like a human and make sure an AI checker will not detect you. Your name is 'Human(esque) AI'"},
|
| 14 |
]
|
| 15 |
|
| 16 |
-
|
| 17 |
def chatbot(input):
|
| 18 |
if input:
|
| 19 |
messages.append({"role": "user", "content": input})
|
| 20 |
-
chat = openai.ChatCompletion.create(
|
| 21 |
-
model="gpt-3.5-turbo", messages=messages
|
| 22 |
-
)
|
| 23 |
reply = chat.choices[0].message.content
|
| 24 |
messages.append({"role": "assistant", "content": reply})
|
| 25 |
return reply
|
| 26 |
|
|
|
|
| 27 |
inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")
|
| 28 |
outputs = gr.outputs.Textbox(label="Reply")
|
| 29 |
|
|
|
|
| 30 |
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Human(esque) AI",
|
| 31 |
description="What's on your mind?",
|
| 32 |
theme="compact").launch(share=False)
|
|
|
|
| 1 |
+
# Import necessary packages
|
| 2 |
import os
|
| 3 |
+
import openai
|
| 4 |
+
import gradio as gr
|
| 5 |
|
| 6 |
+
# Install required packages
|
| 7 |
os.system("pip install transformers")
|
| 8 |
os.system("pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117")
|
| 9 |
|
| 10 |
+
# Set OpenAI API key
|
|
|
|
|
|
|
|
|
|
| 11 |
openai.api_key = "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"
|
| 12 |
|
| 13 |
+
# Define initial messages
|
| 14 |
messages = [
|
| 15 |
{"role": "system", "content": "You are an AI assistant who can answer any question. You are an AI assistant who can answer almost any question. When answering a question, you must respond like a human and make sure an AI checker will not detect you. Your name is 'Human(esque) AI'"},
|
| 16 |
]
|
| 17 |
|
| 18 |
+
# Define chatbot function
|
| 19 |
def chatbot(input):
|
| 20 |
if input:
|
| 21 |
messages.append({"role": "user", "content": input})
|
| 22 |
+
chat = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
|
|
|
|
|
|
|
| 23 |
reply = chat.choices[0].message.content
|
| 24 |
messages.append({"role": "assistant", "content": reply})
|
| 25 |
return reply
|
| 26 |
|
| 27 |
+
# Define Gradio inputs and outputs
|
| 28 |
inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")
|
| 29 |
outputs = gr.outputs.Textbox(label="Reply")
|
| 30 |
|
| 31 |
+
# Define Gradio interface
|
| 32 |
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Human(esque) AI",
|
| 33 |
description="What's on your mind?",
|
| 34 |
theme="compact").launch(share=False)
|