-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pedro Magno Müller
committed
Dec 4, 2022
0 parents
commit f43d328
Showing
36 changed files
with
432 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
venv | ||
.env | ||
config.py |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks.""" | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'twittermachine.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
asgiref==3.5.2 | ||
certifi==2022.9.24 | ||
charset-normalizer==2.1.1 | ||
config==0.5.1 | ||
Django==4.1.3 | ||
et-xmlfile==1.1.0 | ||
idna==3.4 | ||
numpy==1.23.5 | ||
oauthlib==3.2.2 | ||
openai==0.25.0 | ||
openpyxl==3.0.10 | ||
pandas==1.5.2 | ||
pandas-stubs==1.5.2.221124 | ||
python-dateutil==2.8.2 | ||
pytz==2022.6 | ||
requests==2.28.1 | ||
requests-oauthlib==1.3.1 | ||
six==1.16.0 | ||
sqlparse==0.4.3 | ||
tqdm==4.64.1 | ||
tweepy==4.12.1 | ||
types-pytz==2022.6.0.1 | ||
typing_extensions==4.4.0 | ||
urllib3==1.26.13 |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.contrib import admin | ||
from .models import TextBlock | ||
# Register your models here. | ||
|
||
|
||
admin.site.register(TextBlock) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ThemachineConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "themachine" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 4.1.3 on 2022-12-03 09:59 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="TextBlock", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("text", models.TextField(blank=True)), | ||
("tweet", models.TextField(blank=True)), | ||
], | ||
), | ||
] |
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.db import models | ||
from .utils import create_tweet | ||
|
||
# Create your models here. | ||
|
||
class TextBlock(models.Model): | ||
text = models.TextField(blank=True) | ||
tweet = models.TextField(blank=True) | ||
|
||
def save(self) -> None: | ||
prompt = {} | ||
prompt["hashtag"] = "#thethoughtmachine" | ||
prompt["text"] = "Write an engaging, controversial tweet that has a high probability of getting viral or trending using these words:" + self.text | ||
thething = create_tweet(prompt) | ||
self.tweet = thething | ||
print(thething) | ||
return super().save() | ||
|
||
|
||
|
||
def __str__(self): | ||
return f"{self.text} {self.tweet}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous"> | ||
</head> | ||
{% block content %}{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{% extends 'main.html' %} | ||
{% block content %} | ||
<body> | ||
<div class="px-4 pt-5 my-5 text-center border-bottom"> | ||
<h1 class="display-4 fw-bold">Hello!</h1> | ||
<h3 class="display-4 fw-bold">This is the Thought Machine!</h3> | ||
<div class="col-lg-6 mx-auto"> | ||
<p class="lead mb-4">This is a tool to create tweets using ai for you! I mean, this is the future right? Why would you think of a tweet if ai can do a better, more engagable tweet than yourself?</p> | ||
<p class="lead mb-4">So stop thinking and start zombie-tweeting!</p> | ||
<div class="d-grid gap-2 d-sm-flex justify-content-sm-center mb-5"> | ||
<a class="btn btn-primary btn-lg px-4 me-sm-3" href="{% url 'create-tweet' %}">Create Zombie Tweet</a> | ||
{% comment %} <button type="button" class="btn btn-outline-secondary btn-lg px-4">Secondary</button> {% endcomment %} | ||
</div> | ||
</div> | ||
<div class="overflow-hidden"> | ||
<div class="container px-5"> | ||
<table class="table"> | ||
|
||
<thead> | ||
<tr> | ||
<th scope="col">#</th> | ||
<th scope="col">Text</th> | ||
<th scope="col">Tweet</th> | ||
</tr> | ||
</thead> | ||
{% for textblock in object_list %} | ||
<tbody> | ||
<tr> | ||
<th scope="row">{{ forloop.counter }}</th> | ||
<td>{{ textblock.text }}</td> | ||
<td>{{ textblock.tweet }}</td> | ||
</tr> | ||
</tbody> | ||
{% endfor %} | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> | ||
{% endblock %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends 'main.html' %} | ||
{% load i18n %} | ||
{% load crispy_forms_tags %} | ||
|
||
{% block content %} | ||
<form action="" method="post" class="general"> | ||
<div class="form-group container"> | ||
<h1>Twitter Machine</h1> | ||
<h5>Write some ideas keyword so the machine can create a tweet based on that!</h5> | ||
{% csrf_token %} | ||
{{ form|crispy }} | ||
<div class="col-span-3 flex justify-end"> | ||
<input type="submit"> | ||
</div> | ||
</div> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
path( | ||
"", views.HomeView.as_view(), name="home" | ||
), | ||
path("create-tweet/", views.TextBlockCreateView.as_view(), name="create-tweet" | ||
), | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import random, config | ||
|
||
import openai, tweepy | ||
|
||
#OpenAI API credentials | ||
openai.api_key =config.open_ai_key | ||
|
||
print("Connected to Twitter") | ||
|
||
|
||
def create_tweet(prompt): | ||
text = prompt["text"] | ||
hashtags = prompt["hashtag"] | ||
|
||
response = openai.Completion.create( | ||
engine="text-davinci-001", | ||
prompt=text, | ||
max_tokens=50, | ||
) | ||
|
||
tweet = response.choices[0].text | ||
tweet = tweet + " " + hashtags + " " + "#ai #openai #gpt3" | ||
return tweet | ||
|
||
# tweet = create_tweet() | ||
# api.update_status(tweet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.shortcuts import render | ||
from django.http import HttpResponse | ||
from django.urls import reverse | ||
from django.views.generic import TemplateView, CreateView, ListView | ||
|
||
from .models import TextBlock | ||
|
||
|
||
# Create your views here. | ||
class TextBlockCreateView(CreateView): | ||
model = TextBlock | ||
fields = ['text'] | ||
template_name = "themachine/textblock_form.html" | ||
|
||
def get_success_url(self): | ||
return reverse("home") | ||
|
||
|
||
|
||
class HomeView(ListView): | ||
template_name = "themachine/home.html" | ||
model = TextBlock | ||
queryset = TextBlock.objects.all().order_by('-id')[:10] | ||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
return context | ||
|
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for twittermachine project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'twittermachine.settings') | ||
|
||
application = get_asgi_application() |
Oops, something went wrong.