Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
from datetime import datetime | |
import random | |
# Simplified simulation for demo purposes | |
class SimpleOasisDemo: | |
def __init__(self): | |
self.agents = [] | |
self.posts = [] | |
self.interactions = [] | |
self.simulation_running = False | |
def create_sample_agents(self, num_agents=5): | |
"""Create sample agents for demo""" | |
agent_profiles = [ | |
{"id": 1, "name": "Alice", "interests": ["technology", "AI"], "personality": "curious"}, | |
{"id": 2, "name": "Bob", "interests": ["sports", "fitness"], "personality": "active"}, | |
{"id": 3, "name": "Carol", "interests": ["art", "music"], "personality": "creative"}, | |
{"id": 4, "name": "David", "interests": ["politics", "news"], "personality": "analytical"}, | |
{"id": 5, "name": "Eve", "interests": ["travel", "food"], "personality": "adventurous"} | |
] | |
self.agents = agent_profiles[:num_agents] | |
return f"Created {num_agents} agents: {', '.join([agent['name'] for agent in self.agents])}" | |
def simulate_posts(self, topic="general", num_posts=3): | |
"""Simulate posts creation""" | |
sample_posts = { | |
"technology": [ | |
"Just read about the latest AI breakthrough! π€", | |
"The future of quantum computing looks promising", | |
"New smartphone features are getting crazy good" | |
], | |
"sports": [ | |
"Great game last night! π", | |
"Training hard for the marathon next month", | |
"Team performance was outstanding today" | |
], | |
"general": [ | |
"Beautiful sunset today! π ", | |
"Coffee tastes better on Monday mornings β", | |
"Weekend plans: relax and recharge" | |
] | |
} | |
posts_to_create = sample_posts.get(topic, sample_posts["general"]) | |
for i in range(min(num_posts, len(posts_to_create))): | |
if i < len(self.agents): | |
post = { | |
"id": len(self.posts) + 1, | |
"author": self.agents[i]["name"], | |
"content": posts_to_create[i], | |
"timestamp": datetime.now().strftime("%H:%M:%S"), | |
"likes": random.randint(0, 10), | |
"reposts": random.randint(0, 5) | |
} | |
self.posts.append(post) | |
return f"Created {min(num_posts, len(posts_to_create))} posts about {topic}" | |
def simulate_interactions(self): | |
"""Simulate agent interactions""" | |
if not self.posts: | |
return "No posts to interact with. Create some posts first!" | |
interactions = [] | |
for agent in self.agents: | |
# Random chance to interact with posts | |
if random.random() < 0.7: # 70% chance to interact | |
post = random.choice(self.posts) | |
action = random.choice(["like", "repost", "comment"]) | |
interaction = { | |
"agent": agent["name"], | |
"action": action, | |
"post_id": post["id"], | |
"post_author": post["author"], | |
"timestamp": datetime.now().strftime("%H:%M:%S") | |
} | |
if action == "like": | |
post["likes"] += 1 | |
elif action == "repost": | |
post["reposts"] += 1 | |
interactions.append(interaction) | |
self.interactions.append(interaction) | |
return f"Generated {len(interactions)} interactions" | |
def get_simulation_status(self): | |
"""Get current simulation status""" | |
status = f""" | |
**Simulation Status:** | |
- Agents: {len(self.agents)} | |
- Posts: {len(self.posts)} | |
- Interactions: {len(self.interactions)} | |
""" | |
return status | |
def get_posts_display(self): | |
"""Format posts for display""" | |
if not self.posts: | |
return "No posts yet. Start the simulation!" | |
posts_text = "**Recent Posts:**\n\n" | |
for post in self.posts[-5:]: # Show last 5 posts | |
posts_text += f"**{post['author']}** ({post['timestamp']})\n" | |
posts_text += f"{post['content']}\n" | |
posts_text += f"π {post['likes']} | π {post['reposts']}\n\n" | |
return posts_text | |
def get_interactions_display(self): | |
"""Format interactions for display""" | |
if not self.interactions: | |
return "No interactions yet." | |
interactions_text = "**Recent Interactions:**\n\n" | |
for interaction in self.interactions[-10:]: # Show last 10 interactions | |
interactions_text += f"**{interaction['agent']}** {interaction['action']}d post by **{interaction['post_author']}** ({interaction['timestamp']})\n" | |
return interactions_text | |
# Initialize demo | |
demo_instance = SimpleOasisDemo() | |
def run_simulation_step(num_agents, topic, num_posts): | |
"""Run one step of simulation""" | |
results = [] | |
# Create agents | |
if not demo_instance.agents or len(demo_instance.agents) != num_agents: | |
result = demo_instance.create_sample_agents(num_agents) | |
results.append(result) | |
# Create posts | |
result = demo_instance.simulate_posts(topic, num_posts) | |
results.append(result) | |
# Simulate interactions | |
result = demo_instance.simulate_interactions() | |
results.append(result) | |
# Get displays | |
status = demo_instance.get_simulation_status() | |
posts = demo_instance.get_posts_display() | |
interactions = demo_instance.get_interactions_display() | |
return status, posts, interactions, "\n".join(results) | |
def reset_simulation(): | |
"""Reset the simulation""" | |
demo_instance.agents = [] | |
demo_instance.posts = [] | |
demo_instance.interactions = [] | |
return "Simulation reset!", "", "", "" | |
# Create Gradio interface | |
with gr.Blocks(title="OASIS Demo - Social Media Simulation", theme=gr.themes.Soft()) as app: | |
gr.Markdown(""" | |
# ποΈ OASIS Demo: Open Agent Social Interaction Simulations | |
This is a simplified demo of OASIS - a scalable social media simulator with AI agents. | |
**Features demonstrated:** | |
- Multi-agent social interactions | |
- Post creation and engagement | |
- Real-time simulation updates | |
**Note:** This is a simplified version for demonstration. The full OASIS supports up to 1 million agents! | |
""") | |
with gr.Row(): | |
with gr.Column(scale=1): | |
gr.Markdown("### Simulation Controls") | |
num_agents = gr.Slider( | |
minimum=2, | |
maximum=5, | |
value=3, | |
step=1, | |
label="Number of Agents" | |
) | |
topic = gr.Dropdown( | |
choices=["general", "technology", "sports"], | |
value="general", | |
label="Post Topic" | |
) | |
num_posts = gr.Slider( | |
minimum=1, | |
maximum=5, | |
value=2, | |
step=1, | |
label="Posts per Step" | |
) | |
run_btn = gr.Button("π Run Simulation Step", variant="primary") | |
reset_btn = gr.Button("π Reset Simulation", variant="secondary") | |
status_output = gr.Textbox( | |
label="Simulation Status", | |
lines=4, | |
interactive=False | |
) | |
log_output = gr.Textbox( | |
label="Action Log", | |
lines=3, | |
interactive=False | |
) | |
with gr.Column(scale=2): | |
gr.Markdown("### Simulation Output") | |
posts_output = gr.Markdown( | |
value="No posts yet. Start the simulation!", | |
label="Posts Feed" | |
) | |
interactions_output = gr.Markdown( | |
value="No interactions yet.", | |
label="Interactions Feed" | |
) | |
gr.Markdown(""" | |
### About OASIS | |
OASIS (Open Agent Social Interaction Simulations) is a research framework for studying social media dynamics at scale: | |
- **Scalable**: Supports up to 1 million AI agents | |
- **Realistic**: Agents exhibit human-like social behaviors | |
- **Flexible**: Supports multiple platforms (Twitter, Reddit) | |
- **Research-focused**: Study information spread, polarization, and social phenomena | |
**Repository:** [github.com/camel-ai/oasis](https://github.com/camel-ai/oasis) | |
**Documentation:** [docs.oasis.camel-ai.org](https://docs.oasis.camel-ai.org) | |
""") | |
# Event handlers | |
run_btn.click( | |
fn=run_simulation_step, | |
inputs=[num_agents, topic, num_posts], | |
outputs=[status_output, posts_output, interactions_output, log_output] | |
) | |
reset_btn.click( | |
fn=reset_simulation, | |
outputs=[status_output, posts_output, interactions_output, log_output] | |
) | |
if __name__ == "__main__": | |
app.launch(server_name="0.0.0.0", server_port=7860, share=False) | |