jonowrenn commited on
Commit
2149ac3
·
1 Parent(s): 7807a81

Initial commit

Browse files
Files changed (3) hide show
  1. README.md +14 -13
  2. app.py +33 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,13 +1,14 @@
1
- ---
2
- title: Gpt Chatbot
3
- emoji: 🔥
4
- colorFrom: red
5
- colorTo: pink
6
- sdk: gradio
7
- sdk_version: 5.42.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
+ # GPT Chatbot
2
+
3
+ A simple web-based chatbot powered by OpenAI's GPT-3.5-turbo, built with Gradio and deployed on Hugging Face Spaces.
4
+
5
+ ## Features
6
+ - Friendly conversational UI
7
+ - Runs fully in the cloud
8
+ - Powered by OpenAI's API
9
+
10
+ ## How to Run
11
+ This app is designed to run securely on Hugging Face Spaces. Make sure to set your `OPENAI_API_KEY` under the **Secrets** tab.
12
+
13
+ ## Demo
14
+ [Click here to view the live demo](https://huggingface.co/spaces/jonowrenn/gpt-chatbot)
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+ import os
4
+
5
+ # Load your OpenAI API key from the Hugging Face Secrets
6
+ openai.api_key = os.getenv("OPENAI_API_KEY")
7
+
8
+ def chat(user_input):
9
+ try:
10
+ messages = [
11
+ {"role": "system", "content": "You are a helpful and conversational chatbot."},
12
+ {"role": "user", "content": user_input}
13
+ ]
14
+
15
+ response = openai.ChatCompletion.create(
16
+ model="gpt-3.5-turbo",
17
+ messages=messages
18
+ )
19
+ return response.choices[0].message["content"].strip()
20
+
21
+ except Exception as e:
22
+ return f"Error: {e}"
23
+
24
+ # Gradio UI
25
+ interface = gr.Interface(
26
+ fn=chat,
27
+ inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."),
28
+ outputs="text",
29
+ title="GPT Chatbot",
30
+ description="A simple chatbot powered by OpenAI GPT-3.5. Enter a prompt and receive a response."
31
+ )
32
+
33
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai
2
+ gradio