Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
nyacg committed Mar 24, 2024
2 parents c4213e9 + 9ee091a commit fbd553a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
25 changes: 25 additions & 0 deletions ifs.ai/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ export default function Page({ searchParams }: { searchParams: { id: number } })
sidebarRef.current.scrollTop = sidebarRef.current.scrollHeight;
}
});

const createVideo = async (imageUrl: string, text: string) => {
const response = await fetch('http://localhost:5000/create_talk', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
image_url: imageUrl,
text: text
})
});
const data = await response.json();
return data;
}

return (
<main className="flex min-h-svh flex-col px-4 py-10">
Expand Down Expand Up @@ -120,6 +135,16 @@ export default function Page({ searchParams }: { searchParams: { id: number } })
setPrevPart(responder);
setInputValue("");
console.log(data);

const part = parts.find(part => part.name.toLowerCase() === responder.toLowerCase());
if (part) {
console.log("using image")
console.log(part.imageUrl)
// TODO: CAN SOMEOONE LOOK INTO HOW TO DISPLAY IT ON PAGE? SHOULD WE USE THE DIDVideoStream?
console.log(createVideo(part.imageUrl, text));
} else {
console.error('Part not found for responder:', responder);
}
})
.catch((error) => {
console.error("Error:", error);
Expand Down
8 changes: 5 additions & 3 deletions ifs.py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
flask run --debug

curl --location --request POST 'http://127.0.0.1:5000/create_talk' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'image_url=https://images.generated.photos/96rFpeEfKms51LK-Re3qlY8kk_q0pNVB7vC9BYcjfyo/rs:fit:256:256/czM6Ly9pY29uczgu/Z3Bob3Rvcy1wcm9k/LnBob3Rvcy92M18w/MDczMjE2LmpwZw.jpg' \
--data-urlencode 'text=This is an example string of text to be replaced!'
--header 'Content-Type: application/json' \
--data-raw '{
"image_url": "https://replicate.delivery/pbxt/UWXPfBHHc5X1EC3ZuS7YfBaWKzz6xkxmJ6RSbUNbiHa0IhjSA/image_0.png",
"text": "This is an example string of text to be replaced!"
}'
```

### New requirements
Expand Down
26 changes: 17 additions & 9 deletions ifs.py/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
load_dotenv()

groq = os.getenv("GROQ_ENV")
openai_client = OpenAI()
instructor_client = instructor.patch(
OpenAI(
# This is the default and can be omitted
Expand All @@ -34,7 +35,7 @@
D_ID_API_KEY = os.getenv("D_ID_API_KEY")
if D_ID_API_KEY is None:
raise Exception("D_ID_API_KEY not found in environment")
auth = "Bearer " + D_ID_API_KEY
auth = "Basic " + D_ID_API_KEY


# To test this:
Expand Down Expand Up @@ -107,7 +108,7 @@ def get_response():
},
]

response = openapi_client.chat.completions.create(
response = openai_client.chat.completions.create(
model="gpt-4",
messages=messages,
max_tokens=300,
Expand All @@ -124,7 +125,7 @@ def get_response():
responder = "exile"
system = exile_system

system += f" Reply with less than three sentences in first person as a {responder}"
system += f" Reply with less than 2 sentences in first person as a {responder}"
messages = [
ChatMessage(role="system", content=system),
]
Expand Down Expand Up @@ -172,10 +173,13 @@ def get_talk(talk_id):

@app.route('/create_talk', methods=['POST'])
def create_talk():

url = "https://api.d-id.com/talks"

# parse body as json:
request_payload = request.get_json()
text = request_payload.get('text')
image_url = request_payload.get('image_url')

print("rpayload:", request_payload)
payload = {
Expand All @@ -186,13 +190,13 @@ def create_talk():
"type": "microsoft",
"voice_id": "en-US-JennyNeural"
},
"input": request_payload.get('text'),
"input": text,
},
"config": {
"fluent": "false",
"pad_audio": "0.0"
},
"source_url": request_payload.get('image_url'),
"source_url": image_url,
}
headers = {
"accept": "application/json",
Expand All @@ -203,10 +207,14 @@ def create_talk():
response = requests.post(url, json=payload, headers=headers)

print(response.text)
talk_id = json.loads(response.text)['id']
response_json = json.loads(response.text)
if "id" in response_json:
talk_id = response_json['id']

while talk_ready(talk_id) == False:
time.sleep(1)
while talk_ready(talk_id) == False:
time.sleep(1)

return get_talk(talk_id)
return get_talk(talk_id)
else:
return "Error creating talk. ID not found in response JSON"

0 comments on commit fbd553a

Please sign in to comment.