final updates and fixes

This commit is contained in:
Alexander Karpov 2023-08-27 04:15:52 +03:00
parent 8a000dc1e3
commit 18e43129fe
8 changed files with 59 additions and 20 deletions

View File

@ -112,8 +112,8 @@ def create_hints(description: str, stage: int):
].group() ].group()
if not len(filtered_content): if not len(filtered_content):
raise ValueError(f"answer doesnt pass validation, {filtered_content}") raise ValueError(f"answer doesnt pass validation, {filtered_content}")
except: except Exception:
raise ValueError(f"answer doesnt pass validation, {filtered_content}") print(f"answer doesnt pass validation")
content = literal_eval(filtered_content) content = literal_eval(filtered_content)
for assertion_statement in assertions[stage]: for assertion_statement in assertions[stage]:
assert assertion_statement(content) assert assertion_statement(content)

View File

@ -17,11 +17,12 @@
class BasePitchDeckSerializer(serializers.ModelSerializer): class BasePitchDeckSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = PitchDeck model = PitchDeck
fields = ["id", "name", "description", "logo", "created", "updated"] fields = ["id", "name", "description", "logo", "created", "images", "updated"]
extra_kwargs = { extra_kwargs = {
"id": {"read_only": True}, "id": {"read_only": True},
"logo": {"read_only": True}, "logo": {"read_only": True},
"name": {"read_only": True}, "name": {"read_only": True},
"images": {"read_only": True},
"created": {"read_only": True}, "created": {"read_only": True},
"updated": {"read_only": True}, "updated": {"read_only": True},
} }
@ -138,8 +139,8 @@ def validate(self, data):
raise serializers.ValidationError("Value to found") raise serializers.ValidationError("Value to found")
if not isinstance(answer[slug], (int, float)): if not isinstance(answer[slug], (int, float)):
raise serializers.ValidationError("Incorrect type") raise serializers.ValidationError("Incorrect type")
if not (params["min_value"] <= answer[slug] <= params["max_value"]): # if not (params["min_value"] <= answer[slug] <= params["max_value"]):
raise serializers.ValidationError("Number is too big or too small") # raise serializers.ValidationError("Number is too big or too small")
case "multiple_range": case "multiple_range":
scrollbars = {} scrollbars = {}
for el in params["scrollbars"]: for el in params["scrollbars"]:
@ -149,14 +150,14 @@ def validate(self, data):
raise serializers.ValidationError(f"Value {slug} to found") raise serializers.ValidationError(f"Value {slug} to found")
if not isinstance(answer[slug], (int, float)): if not isinstance(answer[slug], (int, float)):
raise serializers.ValidationError(f"Incorrect {slug} type") raise serializers.ValidationError(f"Incorrect {slug} type")
if not ( # if not (
scrollbars[slug]["min_value"] # scrollbars[slug]["min_value"]
<= answer[slug] # <= answer[slug]
<= scrollbars[slug]["max_value"] # <= scrollbars[slug]["max_value"]
): # ):
raise serializers.ValidationError( # raise serializers.ValidationError(
f"Number is too big or too small for {slug}" # f"Number is too big or too small for {slug}"
) # )
case "select": case "select":
if answer not in params["options"]: if answer not in params["options"]:
raise serializers.ValidationError("No such option") raise serializers.ValidationError("No such option")

View File

@ -91,7 +91,7 @@ class GetDeckPresentationDataApiView(generics.GenericAPIView):
10: ["how_much_investments", "time_to_spend", "investments_sold"], 10: ["how_much_investments", "time_to_spend", "investments_sold"],
11: ["company_value", "future_value", "time_to_spend"], 11: ["company_value", "future_value", "time_to_spend"],
12: ["aims"], 12: ["aims"],
13: ["images"], 13: ["images", "links"],
} }
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):

View File

@ -0,0 +1,18 @@
# Generated by Django 4.2.4 on 2023-08-26 23:06
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("decks", "0008_pdftopptxstorage_alter_question_type"),
]
operations = [
migrations.AddField(
model_name="pitchdeck",
name="images",
field=models.JSONField(null=True),
),
]

View File

@ -11,6 +11,7 @@ class PitchDeck(models.Model):
# generated info # generated info
logo = models.ImageField(upload_to="logos/", null=True, blank=True) logo = models.ImageField(upload_to="logos/", null=True, blank=True)
images = models.JSONField(null=True)
styles = models.FileField(upload_to="styles/", null=True, blank=True) styles = models.FileField(upload_to="styles/", null=True, blank=True)
presentation = models.FileField(upload_to="logos/", null=True, blank=True) presentation = models.FileField(upload_to="logos/", null=True, blank=True)
meta_info = models.JSONField(default=dict, null=True, blank=True) meta_info = models.JSONField(default=dict, null=True, blank=True)

View File

@ -15,7 +15,7 @@ def get_image_mokeup(image_path):
) )
else: else:
q = mockup.generate( q = mockup.generate(
template_id=mockup.templates[0].id, template_id="d95345535d98fcc6f4030e1d3ca62052",
screenshot_path=image_path, screenshot_path=image_path,
color=mockup.templates[0].colors[0].color, color=mockup.templates[0].colors[0].color,
) )

View File

@ -34,7 +34,7 @@ def question_answer_create(sender, instance: QuestionAnswer, created, **kwargs):
kwargs={"pk": instance.deck.pk}, countdown=1 kwargs={"pk": instance.deck.pk}, countdown=1
) )
elif instance.question.inner_tag == "names": elif instance.question.inner_tag == "names":
instance.deck.name = instance.answer instance.deck.name = instance.answer if instance.answer else None
instance.deck.save() instance.deck.save()
elif instance.question.inner_tag in ["finance_model"]: elif instance.question.inner_tag in ["finance_model"]:
qenerate_answer_qr.apply_async(kwargs={"pk": instance.pk}, countdown=5) qenerate_answer_qr.apply_async(kwargs={"pk": instance.pk}, countdown=5)
@ -50,6 +50,9 @@ def question_answer_update(sender, instance: QuestionAnswer, **kwargs):
generate_numeric_values.apply_async( generate_numeric_values.apply_async(
kwargs={"pk": instance.deck.pk}, countdown=1 kwargs={"pk": instance.deck.pk}, countdown=1
) )
elif instance.question.inner_tag == "names":
instance.deck.name = instance.answer if instance.answer else None
instance.deck.save()
elif instance.question.inner_tag in ["finance_model"]: elif instance.question.inner_tag in ["finance_model"]:
qenerate_answer_qr.apply_async(kwargs={"pk": instance.pk}, countdown=5) qenerate_answer_qr.apply_async(kwargs={"pk": instance.pk}, countdown=5)
elif instance.question.inner_tag == "images": elif instance.question.inner_tag == "images":

View File

@ -15,7 +15,7 @@
) )
from pitch_deck_generator.decks.services import get_image_mokeup from pitch_deck_generator.decks.services import get_image_mokeup
ML_HOST = "https://forty-eggs-slide.loca.lt/" ML_HOST = "https://small-teeth-own.loca.lt/"
data_types = { data_types = {
"names": ("text", 1), "names": ("text", 1),
@ -56,10 +56,11 @@
@shared_task @shared_task
def run_pitch_deck_calculation(pk: int): def run_pitch_deck_calculation(pk: int):
generate_pitch_deck_name.apply_async(kwargs={"pk": pk}) generate_pitch_deck_name.apply_async(kwargs={"pk": pk}, countdown=1)
generate_known_values.apply_async(kwargs={"pk": pk}) generate_known_values.apply_async(kwargs={"pk": pk}, countdown=1)
for i in range(3): for i in range(3):
generate_batch_hints.apply_async(kwargs={"pk": pk, "num": i}, delay=1) generate_batch_hints.apply_async(kwargs={"pk": pk, "num": i}, countdown=1)
generate_pitch_deck_images.apply_async(kwargs={"pk": pk}, countdown=1)
@shared_task @shared_task
@ -74,6 +75,19 @@ def generate_pitch_deck_name(pk: int):
) )
@shared_task
def generate_pitch_deck_images(pk: int):
pitch_deck = PitchDeck.objects.get(pk=pk)
req = requests.post(
ML_HOST + "img-search",
json={"body": pitch_deck.description},
)
print(req.text)
data = req.json()
pitch_deck.images = data
pitch_deck.save()
@shared_task @shared_task
def generate_known_values(pk: int): def generate_known_values(pk: int):
pitch_deck = PitchDeck.objects.get(pk=pk) pitch_deck = PitchDeck.objects.get(pk=pk)
@ -81,6 +95,7 @@ def generate_known_values(pk: int):
ML_HOST + "search", ML_HOST + "search",
json={"body": pitch_deck.description}, json={"body": pitch_deck.description},
) )
print(req.text)
data = req.json() data = req.json()
_, question_id = data_types["competitors"] _, question_id = data_types["competitors"]
QuestionDeckHint.objects.create( QuestionDeckHint.objects.create(
@ -134,6 +149,7 @@ def generate_numeric_values(pk: int):
"type": type, "type": type,
}, },
) )
print(req.text)
data = req.json() data = req.json()
for el in data: for el in data:
question_type, question_id = data_types[el["type"]] question_type, question_id = data_types[el["type"]]