Spaces:
Runtime error
Runtime error
Initial Commit
Browse files- chatgpt_gradio.py +27 -0
chatgpt_gradio.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
openai.api_key = "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"
|
| 5 |
+
|
| 6 |
+
messages=[{"role": "system", "content": "You are a Programming Expert"}]
|
| 7 |
+
|
| 8 |
+
def Custom_GPT(msg):
|
| 9 |
+
messages.append({"role": "user", "content": msg})
|
| 10 |
+
completion = openai.ChatCompletion.create(model='gpt-3.5-turbo', messages=messages)
|
| 11 |
+
response = completion.choices[0].message.content
|
| 12 |
+
messages.append({"role": "system", "content": response})
|
| 13 |
+
return response
|
| 14 |
+
|
| 15 |
+
demo = gr.Interface(fn=Custom_GPT, inputs="text", outputs="text", title="Coder Chatbot")
|
| 16 |
+
|
| 17 |
+
demo.launch(share=True)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|