Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Getting responses using the OpenAI API
|
5 |
+
def answer_chatgpt(api_key, message):
|
6 |
+
# OPENAI API KEY
|
7 |
+
openai.api_key = api_key
|
8 |
+
prompt = (f"You are GPT-3 and answer my following message: {message}")
|
9 |
+
response = openai.Completion.create(
|
10 |
+
engine="text-davinci-003",
|
11 |
+
prompt=prompt,
|
12 |
+
max_tokens=1024
|
13 |
+
)
|
14 |
+
# Displaying the answer on the screen
|
15 |
+
answer = response["choices"][0]["text"]
|
16 |
+
return answer
|
17 |
+
|
18 |
+
# User input
|
19 |
+
chatbot = gr.Interface(
|
20 |
+
fn=answer_chatgpt,
|
21 |
+
inputs=["text", "text"],
|
22 |
+
outputs="text",
|
23 |
+
title="π€ ChatGPT-Python π",
|
24 |
+
description="ChatGPT-Python is a software that allows you to talk to GPT-3 with a web interface using the openai api"
|
25 |
+
)
|
26 |
+
chatbot.launch()
|