jbilcke-hf HF staff commited on
Commit
d85329e
1 Parent(s): 59803ed

mini improvement

Browse files
src/app/interface/generate/index.tsx CHANGED
@@ -35,11 +35,10 @@ export function Generate() {
35
  const [runs, setRuns] = useState(0)
36
  const runsRef = useRef(0)
37
  const [showModels, setShowModels] = useState(true)
38
- // useEffect(() => { runsRef.current = runs }, [runs])
39
 
40
  const [communityRoll, setCommunityRoll] = useState<Post[]>([])
41
 
42
- console.log("runs:", runs)
43
  const { progressPercent, remainingTimeInSec } = useCountdown({
44
  isActive: isLocked,
45
  timerId: runs, // everytime we change this, the timer will reset
@@ -92,9 +91,10 @@ export function Generate() {
92
  const search = current.toString()
93
  router.push(`${pathname}${search ? `?${search}` : ""}`)
94
 
 
95
  try {
96
- console.log("starting transition, calling generateAnimation")
97
- const newAssetUrl = await generateAnimation({
98
  positivePrompt: promptDraft,
99
  negativePrompt: "",
100
  huggingFaceLora,
@@ -106,28 +106,47 @@ export function Generate() {
106
  })
107
  setAssetUrl(newAssetUrl)
108
 
 
 
 
109
  try {
110
- const post = await postToCommunity({
111
- prompt: promptDraft,
112
- model: huggingFaceLora,
113
- assetUrl: newAssetUrl,
 
 
 
 
 
114
  })
115
- console.log("successfully submitted to the community!", post)
116
-
117
- // now you got a read/write object
118
- const current = new URLSearchParams(Array.from(searchParams.entries()))
119
- current.set("postId", post.postId.trim())
120
- current.set("prompt", post.prompt.trim())
121
- current.set("model", post.model.trim())
122
- const search = current.toString()
123
- router.push(`${pathname}${search ? `?${search}` : ""}`)
124
  } catch (err) {
125
- console.error(`not a blocker, but we failed to post to the community (reason: ${err})`)
126
  }
127
- } catch (err) {
128
- console.error(err)
129
  } finally {
130
  setLocked(false)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  }
132
  })
133
  }
 
35
  const [runs, setRuns] = useState(0)
36
  const runsRef = useRef(0)
37
  const [showModels, setShowModels] = useState(true)
 
38
 
39
  const [communityRoll, setCommunityRoll] = useState<Post[]>([])
40
 
41
+
42
  const { progressPercent, remainingTimeInSec } = useCountdown({
43
  isActive: isLocked,
44
  timerId: runs, // everytime we change this, the timer will reset
 
91
  const search = current.toString()
92
  router.push(`${pathname}${search ? `?${search}` : ""}`)
93
 
94
+ let newAssetUrl = ""
95
  try {
96
+ // console.log("starting transition, calling generateAnimation")
97
+ newAssetUrl = await generateAnimation({
98
  positivePrompt: promptDraft,
99
  negativePrompt: "",
100
  huggingFaceLora,
 
106
  })
107
  setAssetUrl(newAssetUrl)
108
 
109
+ } catch (err) {
110
+ console.log("generation failed! probably just a Gradio failure, so let's just run the round robin again!")
111
+
112
  try {
113
+ newAssetUrl = await generateAnimation({
114
+ positivePrompt: promptDraft,
115
+ negativePrompt: "",
116
+ huggingFaceLora,
117
+ triggerWord,
118
+ size: "608x416", // "1024x512", // "512x512" // "320x768"
119
+ nbFrames: 8, // if duration is 1000ms then it means 8 FPS
120
+ duration: 1000, // in ms
121
+ steps: 25,
122
  })
123
+ setAssetUrl(newAssetUrl)
 
 
 
 
 
 
 
 
124
  } catch (err) {
125
+ console.error(`generation failed again! ${err}`)
126
  }
 
 
127
  } finally {
128
  setLocked(false)
129
+
130
+ if (newAssetUrl) {
131
+ try {
132
+ const post = await postToCommunity({
133
+ prompt: promptDraft,
134
+ model: huggingFaceLora,
135
+ assetUrl: newAssetUrl,
136
+ })
137
+ console.log("successfully submitted to the community!", post)
138
+
139
+ // now you got a read/write object
140
+ const current = new URLSearchParams(Array.from(searchParams.entries()))
141
+ current.set("postId", post.postId.trim())
142
+ current.set("prompt", post.prompt.trim())
143
+ current.set("model", post.model.trim())
144
+ const search = current.toString()
145
+ router.push(`${pathname}${search ? `?${search}` : ""}`)
146
+ } catch (err) {
147
+ console.error(`not a blocker, but we failed to post to the community (reason: ${err})`)
148
+ }
149
+ }
150
  }
151
  })
152
  }
src/lib/useCountdown.ts CHANGED
@@ -30,7 +30,7 @@ export function useCountdown({
30
  const newElapsedInMs = Math.min(durationInMs, now.getTime() - startedAt.current!.getTime())
31
  setElapsedTimeInMs(newElapsedInMs)
32
  if (elapsedTimeInMs > durationInMs) {
33
- console.log("end of timer")
34
  clearInterval(intervalRef.current)
35
  onEnd()
36
  }
@@ -38,7 +38,7 @@ export function useCountdown({
38
  }
39
 
40
  return () => {
41
- console.log("destruction of timer")
42
  clearInterval(intervalRef.current)
43
  }
44
  }, [isActive, timerId, durationInMs])
 
30
  const newElapsedInMs = Math.min(durationInMs, now.getTime() - startedAt.current!.getTime())
31
  setElapsedTimeInMs(newElapsedInMs)
32
  if (elapsedTimeInMs > durationInMs) {
33
+ // console.log("end of timer")
34
  clearInterval(intervalRef.current)
35
  onEnd()
36
  }
 
38
  }
39
 
40
  return () => {
41
+ // console.log("destruction of timer")
42
  clearInterval(intervalRef.current)
43
  }
44
  }, [isActive, timerId, durationInMs])