-
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.
Merge pull request #16 from christianbmartinez/tmp
Tmp
- Loading branch information
Showing
10 changed files
with
423 additions
and
200 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
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
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
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
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,38 @@ | ||
export default async function create_image(description: string) { | ||
try { | ||
const payload = { | ||
model: 'dall-e-3', | ||
prompt: description, | ||
n: 1, | ||
size: '1024x1024', | ||
response_format: 'url', | ||
quality: 'hd', | ||
} | ||
|
||
const response = await fetch( | ||
'https://api.openai.com/v1/images/generations', | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`, | ||
}, | ||
method: 'POST', | ||
body: JSON.stringify(payload), | ||
} | ||
) | ||
|
||
if (!response.ok) { | ||
throw new Error('Image data not available') | ||
} | ||
|
||
const image = await response.json() | ||
|
||
return { | ||
description: description, | ||
url: `${image.data[0].url}`, | ||
} | ||
} catch (error) { | ||
console.log(error) | ||
throw error | ||
} | ||
} |
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,37 @@ | ||
import Replicate from 'replicate' | ||
|
||
export default async function create_video(description: string) { | ||
try { | ||
const replicate = new Replicate({ | ||
auth: process.env.REPLICATE_API_TOKEN, | ||
}) | ||
|
||
const response = await replicate.run( | ||
'anotherjesse/zeroscope-v2-xl:1f0dd155aeff719af56f4a2e516c7f7d4c91a38c7b8e9e81808e7c71bde9b868', | ||
{ | ||
input: { | ||
fps: 24, | ||
fast: true, | ||
width: 576, | ||
height: 320, | ||
prompt: description, | ||
num_frames: 24, | ||
guidance_scale: 17.5, | ||
num_inference_steps: 50, | ||
}, | ||
} | ||
) | ||
|
||
if (!response) { | ||
throw new Error('Video data not available') | ||
} | ||
|
||
return { | ||
description: description, | ||
url: response, | ||
} | ||
} catch (error) { | ||
console.log(error) | ||
throw error | ||
} | ||
} |
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,32 @@ | ||
export default async function get_current_weather( | ||
zipcode: string, | ||
state: string | ||
) { | ||
try { | ||
const response = await fetch( | ||
`http://api.openweathermap.org/data/2.5/weather?zip=${zipcode}&appid=${process.env.WEATHER_APP_ID}&units=imperial` | ||
) | ||
|
||
if (!response.ok) { | ||
throw new Error('Weather data not available') | ||
} | ||
const city = await response.json() | ||
|
||
const celcius = ((city.main.temp - 32) * 5) / 9 | ||
|
||
return { | ||
temperature: `${city.main.temp}°F`, | ||
celcius: `${Math.round(celcius * 100) / 100}°C`, | ||
location: `${city.name}`, | ||
url: `https://openweathermap.org/img/wn/${city.weather[0].icon}@2x.png`, | ||
description: `${city.weather[0].description}`, | ||
humidity: `${city.main.humidity}%`, | ||
wind: `${city.wind.speed}m/h`, | ||
clouds: `${city.clouds.all}%`, | ||
state: state, | ||
} | ||
} catch (error) { | ||
console.log(error) | ||
throw error | ||
} | ||
} |
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 @@ | ||
export { default as create_image } from './create_image' | ||
export { default as create_video } from './create_video' | ||
export { default as get_current_weather } from './get_current_weather' |
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 |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
*/ | ||
|
||
export * from './components' | ||
export * from './helpers' | ||
export * from './hooks' | ||
export * from './types' |