jbilcke-hf HF staff commited on
Commit
038c38b
1 Parent(s): bdb5fb4
src/app/engine/community.ts CHANGED
@@ -11,10 +11,12 @@ const appId = `${process.env.COMMUNITY_API_ID || ""}`
11
  const secretModerationKey = `${process.env.MODERATION_KEY || ""}`
12
 
13
  export async function postToCommunity({
14
- prompt,
15
- assetUrl,
 
16
  }: {
17
  prompt: string
 
18
  assetUrl: string
19
  }): Promise<Post> {
20
 
@@ -32,6 +34,7 @@ export async function postToCommunity({
32
  postId: uuidv4(),
33
  appId: "mock",
34
  prompt,
 
35
  previewUrl: assetUrl,
36
  assetUrl,
37
  createdAt: new Date().toISOString(),
@@ -78,7 +81,7 @@ export async function postToCommunity({
78
  // You can return Date, Map, Set, etc.
79
 
80
  // Recommendation: handle errors
81
- if (res.status !== 200) {
82
  // This will activate the closest `error.js` Error Boundary
83
  throw new Error('Failed to fetch data')
84
  }
@@ -93,7 +96,13 @@ export async function postToCommunity({
93
  }
94
  }
95
 
96
- export async function getLatestPosts(visibility?: PostVisibility): Promise<Post[]> {
 
 
 
 
 
 
97
 
98
  let posts: Post[] = []
99
 
@@ -105,6 +114,7 @@ export async function getLatestPosts(visibility?: PostVisibility): Promise<Post[
105
 
106
  try {
107
  // console.log(`calling GET ${apiUrl}/posts with renderId: ${renderId}`)
 
108
  const res = await fetch(`${apiUrl}/posts/${appId}/${
109
  visibility || "all"
110
  }`, {
@@ -132,7 +142,6 @@ export async function getLatestPosts(visibility?: PostVisibility): Promise<Post[
132
  const response = (await res.json()) as GetAppPostsResponse
133
  // console.log("response:", response)
134
 
135
- const maxNbPosts = 500
136
  const posts: Post[] = Array.isArray(response?.posts) ? response?.posts : []
137
  posts.sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt))
138
  return posts.slice(0, maxNbPosts)
 
11
  const secretModerationKey = `${process.env.MODERATION_KEY || ""}`
12
 
13
  export async function postToCommunity({
14
+ prompt = "",
15
+ model = "",
16
+ assetUrl = "",
17
  }: {
18
  prompt: string
19
+ model: string,
20
  assetUrl: string
21
  }): Promise<Post> {
22
 
 
34
  postId: uuidv4(),
35
  appId: "mock",
36
  prompt,
37
+ model,
38
  previewUrl: assetUrl,
39
  assetUrl,
40
  createdAt: new Date().toISOString(),
 
81
  // You can return Date, Map, Set, etc.
82
 
83
  // Recommendation: handle errors
84
+ if (res.status !== 201) {
85
  // This will activate the closest `error.js` Error Boundary
86
  throw new Error('Failed to fetch data')
87
  }
 
96
  }
97
  }
98
 
99
+ export async function getLatestPosts({
100
+ visibility,
101
+ maxNbPosts = 1000
102
+ }: {
103
+ visibility?: PostVisibility
104
+ maxNbPosts?: number
105
+ }): Promise<Post[]> {
106
 
107
  let posts: Post[] = []
108
 
 
114
 
115
  try {
116
  // console.log(`calling GET ${apiUrl}/posts with renderId: ${renderId}`)
117
+ // TODO: send the max number of posts
118
  const res = await fetch(`${apiUrl}/posts/${appId}/${
119
  visibility || "all"
120
  }`, {
 
142
  const response = (await res.json()) as GetAppPostsResponse
143
  // console.log("response:", response)
144
 
 
145
  const posts: Post[] = Array.isArray(response?.posts) ? response?.posts : []
146
  posts.sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt))
147
  return posts.slice(0, maxNbPosts)
src/app/firehose/page.tsx CHANGED
@@ -22,7 +22,9 @@ export default function FirehosePage() {
22
 
23
  useEffect(() => {
24
  startTransition(async () => {
25
- const newPosts = await getLatestPosts()
 
 
26
  setPosts(newPosts)
27
  })
28
  }, [])
 
22
 
23
  useEffect(() => {
24
  startTransition(async () => {
25
+ const newPosts = await getLatestPosts({
26
+ maxNbPosts: 50,
27
+ })
28
  setPosts(newPosts)
29
  })
30
  }, [])
src/app/generate/page.tsx CHANGED
@@ -96,6 +96,7 @@ export default function GeneratePage() {
96
  try {
97
  await postToCommunity({
98
  prompt,
 
99
  assetUrl: newRendered.assetUrl,
100
  })
101
  } catch (err) {
 
96
  try {
97
  await postToCommunity({
98
  prompt,
99
+ model: "jbilcke-hf/sdxl-panorama",
100
  assetUrl: newRendered.assetUrl,
101
  })
102
  } catch (err) {
src/types.ts CHANGED
@@ -97,6 +97,7 @@ export type Post = {
97
  postId: string
98
  appId: string
99
  prompt: string
 
100
  previewUrl: string
101
  assetUrl: string
102
  createdAt: string
 
97
  postId: string
98
  appId: string
99
  prompt: string
100
+ model: string
101
  previewUrl: string
102
  assetUrl: string
103
  createdAt: string