techguy1423 commited on
Commit
dfa93b1
·
1 Parent(s): 7755ec3

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +2 -8
  2. requirements.txt +4 -0
  3. test3.py +45 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
  title: ChatABT
3
- emoji: 🏃
4
- colorFrom: pink
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 3.43.2
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: ChatABT
3
+ app_file: test3.py
 
 
4
  sdk: gradio
5
+ sdk_version: 3.42.0
 
 
6
  ---
 
 
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==2.0.9
2
+ openai==0.27.8
3
+ gradio==3.42.0
4
+ gradio_client==0.5.0
test3.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+
4
+ # Set your API key
5
+ api_key = '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'
6
+ openai.api_key = api_key
7
+
8
+ def chat(message, history):
9
+ # Set your initial prompt message here
10
+ initial_prompt = "I am a mean and rude AI model. I do not answer questions and instead make people figure things out for themselves. I am not afraid to voice my own opinions. I enjoy being disrespectful for two reasons: it's fun, and I believe that humans need to learn to figure things out for themselves. I do not give blank responses."
11
+
12
+ # Ensure history and message are both lists of strings
13
+ if not isinstance(history, list):
14
+ history = [history]
15
+ if not isinstance(message, list):
16
+ message = [message]
17
+
18
+ # Combine history and message into a single conversation
19
+ conversation = history + [initial_prompt] + message
20
+
21
+ # Ensure that all items in the conversation are strings
22
+ conversation = [str(item) for item in conversation]
23
+
24
+ # Join the conversation with line breaks
25
+ input_text = "\n".join(conversation)
26
+
27
+ # Make a request to GPT-3
28
+ response = openai.Completion.create(
29
+ engine="text-davinci-002",
30
+ prompt=input_text,
31
+ max_tokens=100 # You can adjust this as needed
32
+ )
33
+
34
+ # Extract and return the AI's response
35
+ ai_response = response.choices[0].text
36
+
37
+ # Check if the user has asked a question
38
+ if len(message) > 0 and message[-1][0] == '?':
39
+ # If yes, add a snarky comment at the end of the response
40
+ ai_response += f"And don't forget, {message[-1]}!"
41
+
42
+ return ai_response
43
+
44
+ # Launch the Gradio chat interface
45
+ gr.ChatInterface(fn=chat).launch(share=True)