Skip to content

Commit

Permalink
Merge pull request #208 from GooeyAI/sticky-submit-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy authored Nov 12, 2023
2 parents 9386cfb + e0f586f commit 0485670
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
22 changes: 17 additions & 5 deletions daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,18 @@ def render_submit_button(self, key="--submit-1"):
col2.node.props[
"className"
] += " d-flex justify-content-end align-items-center"
col1.node.props["className"] += " d-flex flex-column justify-content-center"
with col1:
cost_note = self.get_cost_note() or ""
if cost_note:
cost_note = f"({cost_note.strip()})"
st.caption(
f"Run cost = [{self.get_price_roundoff(st.session_state)} credits]({self.get_credits_click_url()}) \\\n"
f"_By submitting, you agree to Gooey.AI's [terms](https://gooey.ai/terms) & [privacy policy](https://gooey.ai/privacy)._ ",
f"""
Run cost = <a href="{self.get_credits_click_url()}">{self.get_price_roundoff(st.session_state)} credits</a> {cost_note}
{self.additional_notes() or ""}
""",
unsafe_allow_html=True,
)
additional_notes = self.additional_notes()
if additional_notes:
st.caption(additional_notes)
with col2:
submitted = st.button(
"🏃 Submit",
Expand Down Expand Up @@ -632,6 +636,11 @@ def _render_input_col(self):
st.text_input("Title", key=StateKeys.page_title)
st.text_area("Notes", key=StateKeys.page_notes)
submitted = self.render_submit_button()
with st.div(style={"textAlign": "right"}):
st.caption(
"_By submitting, you agree to Gooey.AI's [terms](https://gooey.ai/terms) & "
"[privacy policy](https://gooey.ai/privacy)._"
)
return submitted

def _render_output_col(self, submitted: bool):
Expand Down Expand Up @@ -1141,6 +1150,9 @@ def get_example_response_body(
def additional_notes(self) -> str | None:
pass

def get_cost_note(self) -> str | None:
pass

def is_current_user_admin(self) -> bool:
if not self.request or not self.request.user:
return False
Expand Down
8 changes: 4 additions & 4 deletions recipes/DeforumSD.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ def render_form_v2(self):
"""
)

def get_cost_note(self) -> str | None:
return f"{CREDITS_PER_FRAME} / frame"

def additional_notes(self) -> str | None:
return f"""
*Cost ≈ {CREDITS_PER_FRAME} credits per frame* \\
*Process Run Time ≈ 5 seconds per frame*
"""
return "Render Time ≈ 3s / frame"

def get_raw_price(self, state: dict) -> float:
max_frames = state.get("max_frames", 100) or 0
Expand Down
6 changes: 2 additions & 4 deletions recipes/Lipsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ def render_usage_guide(self):
def preview_description(self, state: dict) -> str:
return "Create high-quality, realistic Lipsync animations from any audio file. Input a sample face gif/video + audio and we will automatically generate a lipsync animation that matches your audio."

def additional_notes(self) -> str | None:
return f"""
*Cost ≈ {CREDITS_PER_MB} credits per MB*
"""
def get_cost_note(self) -> str | None:
return f"{CREDITS_PER_MB} credits per MB"

def get_raw_price(self, state: dict) -> float:
total_bytes = 0
Expand Down
21 changes: 13 additions & 8 deletions recipes/LipsyncTTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,20 @@ def get_raw_price(self, state: dict):
else:
return LipsyncPage.get_raw_price(self, state)

def get_cost_note(self):
return "Lipsync cost + TTS cost"

def additional_notes(self):
lipsync_notes = LipsyncPage.additional_notes(self)
if tts_notes := TextToSpeechPage.additional_notes(self):
notes = f"""
- *Lipsync* {lipsync_notes.strip()}
- *TTS* {tts_notes.strip()}
"""
else:
notes = lipsync_notes
cost_notes = {
"Lipsync": LipsyncPage.get_cost_note(self),
"TTS": TextToSpeechPage.get_cost_note(self),
}
notes = "\n".join(
[f"- *{k} cost: {v.strip()}*" if v else "" for k, v in cost_notes.items()]
)

notes += LipsyncPage.additional_notes(self) or ""
notes += TextToSpeechPage.additional_notes(self) or ""

return notes

Expand Down
6 changes: 3 additions & 3 deletions recipes/TextToSpeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ def _get_tts_provider(self, state: dict):
# TODO: validate tts_provider before lookup?
return TextToSpeechProviders[tts_provider]

def additional_notes(self):
def get_cost_note(self):
tts_provider = st.session_state.get("tts_provider")
if tts_provider == TextToSpeechProviders.ELEVEN_LABS.name:
_, is_user_provided_key = self._get_elevenlabs_api_key(st.session_state)
if is_user_provided_key:
return "*Eleven Labs cost ≈ No additional credit charge given we'll use your API key*"
return "*Eleven Labs ≈ No additional credit charge given we'll use your API key*"
else:
return "*Eleven Labs cost ≈ 4 credits per 10 words*"
return "*Eleven Labs ≈ 4 credits per 10 words*"
else:
return ""

Expand Down
6 changes: 2 additions & 4 deletions recipes/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ def run(self, state: dict):
# Save the raw ASR text for details view
state["output_text"] = asr_output

def additional_notes(self) -> str | None:
return """
*Cost ≈ 1 credit for 12.5 words ≈ 0.08 credits per word*
"""
def get_cost_note(self) -> str | None:
return "1 credit for 12.5 words ≈ 0.08 per word"

def get_raw_price(self, state: dict):
texts = state.get("output_text", [])
Expand Down

0 comments on commit 0485670

Please sign in to comment.