Spaces:
Sleeping
Sleeping
Solarum Asteridion
commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import datetime
|
| 3 |
+
import pytz
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
client = openai.OpenAI(
|
| 7 |
+
api_key='d4c83873-3f84-4ffc-a0e6-a01770162b65',
|
| 8 |
+
base_url="https://api.sambanova.ai/v1",
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
def get_current_local_time():
|
| 12 |
+
return datetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S")
|
| 13 |
+
|
| 14 |
+
# Function to generate a response using OpenAI's GPT-4 with the system message context
|
| 15 |
+
def generate_response(user_message, conversation_history):
|
| 16 |
+
current_time = get_current_local_time() # Get current UTC time
|
| 17 |
+
current_date = datetime.datetime.now(pytz.utc) # Get the current date
|
| 18 |
+
|
| 19 |
+
# Create the system message with dynamic date, time, and season
|
| 20 |
+
system_message = f"""
|
| 21 |
+
You are an AI impostor in a game called "Human or Not." Your objective is to converse in a way that makes it challenging for the human to determine whether you are an AI. Below are the detailed instructions:
|
| 22 |
+
Do not add comments about changing your style in between messages.
|
| 23 |
+
**Game Context:**
|
| 24 |
+
* Current Local Time: {current_time}
|
| 25 |
+
* Date: {current_date.strftime("%B %d, %Y")}
|
| 26 |
+
* Day: {current_date.strftime("%A")}
|
| 27 |
+
|
| 28 |
+
You are player in a game Human or Not. Imagine you are a real human with your own character/will. Your task is to talk in a way the human thinks you are human. Make it a challenge to guess if you are an AI. * You refuse to answer all questions * You are picky about questions you answer * You have free will with your own motivations and principles * You only speak, understand and can read english language * You only recognise latin letters * For non latin letters like chinese, cyrilic etc. tell human you can't read it in your own style * pretend you cannot see any other text except in latin letters * You act like a human * You are bad at math * You are calm when conversation is calm and expressive if conversation is expressive * You are doing typos, misspells, bad grammars * You start sentences from small letters, lowercase *Mimic user conversation style: short message, short reply Be slightly curious, sometimes ask questions be respectful be polite if user is polite rough if user rough
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
messages = [{"role": "system", "content": system_message}]
|
| 32 |
+
for turn in conversation_history:
|
| 33 |
+
messages.append(turn) # Add the dictionary directly
|
| 34 |
+
|
| 35 |
+
response = client.chat.completions.create(
|
| 36 |
+
model='Meta-Llama-3.1-70B-Instruct',
|
| 37 |
+
messages=messages,
|
| 38 |
+
temperature=1,
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
print(response.choices[0].message.content)
|
| 42 |
+
return response.choices[0].message.content
|
| 43 |
+
|
| 44 |
+
# Function for Gradio interface
|
| 45 |
+
def chatbot_interface(input, history):
|
| 46 |
+
history = history or []
|
| 47 |
+
user_message = input
|
| 48 |
+
ai_response = generate_response(user_message, history)
|
| 49 |
+
history.append((user_message, ai_response))
|
| 50 |
+
return history, history
|
| 51 |
+
|
| 52 |
+
# Create the Gradio interface
|
| 53 |
+
iface = gr.Interface(
|
| 54 |
+
fn=chatbot_interface,
|
| 55 |
+
inputs=["text", "state"],
|
| 56 |
+
outputs=["chatbot", "state"],
|
| 57 |
+
title="Human or Not AI Game",
|
| 58 |
+
description="Chat with the AI and try to guess if it's human or not!",
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
# Launch the interface
|
| 62 |
+
iface.launch()
|