ariafyy / Linly-Talker

Digital Avatar Conversational System - Linly-Talker. ๐Ÿ˜„โœจ Linly-Talker is an intelligent AI system that combines large language models (LLMs) with visual models to create a novel human-AI interaction method. ๐Ÿค๐Ÿค– It integrates various technologies like Whisper, Linly, Microsoft Speech Services, and SadTalker talking head generation system. ๐ŸŒŸ๐Ÿ”ฌ

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Digital Avatar Conversational System - Linly-Talker

English ็ฎ€ไฝ“ไธญๆ–‡

2023.12 Update ๐Ÿ“†

Users can upload any images for the conversation

Introduction

Linly-Talker is an intelligent AI system that combines large language models (LLMs) with visual models to create a novel human-AI interaction method. It integrates various technologies like Whisper, Linly, Microsoft Speech Services and SadTalker talking head generation system. The system is deployed on Gradio to allow users to converse with an AI assistant by providing images as prompts. Users can have free-form conversations or generate content according to their preferences.

The system architecture of multimodal humanโ€“computer interaction.

Setup

conda create -n linly python=3.8
conda activate linly

pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113 

conda install ffmpeg

pip install -r requirements_app.txt

ASR - Whisper

Leverages OpenAI's Whisper, see https://github.com/openai/whisper for usage.

TTS - Edge TTS

Uses Microsoft Speech Services, see https://github.com/rany2/edge-tts for usage.

THG - SadTalker

Talking head generation uses SadTalker from CVPR 2023, see https://sadtalker.github.io

Download SadTalker models:

bash scripts/download_models.sh

LLM - Linly

Linly from CVI , Shenzhen University, see https://github.com/CVI-SZU/Linly

Download Linly models: https://huggingface.co/Linly-AI/Chinese-LLaMA-2-7B-hf

git lfs install
git clone https://huggingface.co/Linly-AI/Chinese-LLaMA-2-7B-hf

Or use the API:

# CLI
curl -X POST -H "Content-Type: application/json" -d '{"question": "What are fun places in Beijing?"}' http://url:port

# Python
import requests

url = "http://url:port"  
headers = {
  "Content-Type": "application/json" 
}

data = {
  "question": "What are fun places in Beijing?"
}

response = requests.post(url, headers=headers, json=data)
# response_text = response.content.decode("utf-8")
answer, tag = response.json()
# print(answer)
if tag == 'success':
    response_text =  answer[0]
else:
    print("fail")
print(response_text)

Optimizations

Some optimizations:

  • Use fixed input face images, extract features beforehand to avoid reading each time
  • Remove unnecessary libraries to reduce total time
  • Only save final video output, don't save intermediate results to improve performance
  • Use OpenCV to generate final video instead of mimwrite for faster runtime

Gradio

Gradio is a Python library that provides an easy way to deploy machine learning models as interactive web apps.

For Linly-Talker, Gradio serves two main purposes:

  1. Visualization & Demo: Gradio provides a simple web GUI for the model, allowing users to see the results intuitively by uploading an image and entering text. This is an effective way to showcase the capabilities of the system.

  2. User Interaction: The Gradio GUI can serve as a frontend to allow end users to interact with Linly-Talker. Users can upload their own images and ask arbitrary questions or have conversations to get real-time responses. This provides a more natural speech interaction method.

Specifically, we create a Gradio Interface in app.py that takes image and text inputs, calls our function to generate the response video, and displays it in the GUI. This enables browser interaction without needing to build complex frontend.

In summary, Gradio provides visualization and user interaction interfaces for Linly-Talker, serving as effective means for showcasing system capabilities and enabling end users.

Usage

The folder structure is as follows:

Linly-Talker/
โ”œโ”€โ”€ app.py
โ”œโ”€โ”€ app_img.py 
โ”œโ”€โ”€ utils.py
โ”œโ”€โ”€ Linly-api.py
โ”œโ”€โ”€ Linly-example.ipynb
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ README_zh.md
โ”œโ”€โ”€ request-Linly-api.py
โ”œโ”€โ”€ requirements_app.txt
โ”œโ”€โ”€ scripts
   โ””โ”€โ”€ download_models.sh
โ”œโ”€โ”€ src
   โ””โ”€โ”€ .....
โ”œโ”€โ”€ inputs
   โ”œโ”€โ”€ example.png
   โ””โ”€โ”€ first_frame_dir
       โ”œโ”€โ”€ example_landmarks.txt
       โ”œโ”€โ”€ example.mat
       โ””โ”€โ”€ example.png
โ”œโ”€โ”€ examples
   โ”œโ”€โ”€ driven_audio
      โ”œโ”€โ”€ bus_chinese.wav
      โ”œโ”€โ”€ ......
      โ””โ”€โ”€ RD_Radio40_000.wav
   โ”œโ”€โ”€ ref_video
      โ”œโ”€โ”€ WDA_AlexandriaOcasioCortez_000.mp4
      โ””โ”€โ”€ WDA_KatieHill_000.mp4
   โ””โ”€โ”€ source_image
       โ”œโ”€โ”€ art_0.png
       โ”œโ”€โ”€ ......
       โ””โ”€โ”€ sad.png
โ”œโ”€โ”€ checkpoints // SadTalker model weights path
   โ”œโ”€โ”€ mapping_00109-model.pth.tar
   โ”œโ”€โ”€ mapping_00229-model.pth.tar
   โ”œโ”€โ”€ SadTalker_V0.0.2_256.safetensors
   โ””โ”€โ”€ SadTalker_V0.0.2_512.safetensors
โ”œโ”€โ”€ gfpgan // GFPGAN model weights path
   โ””โ”€โ”€ weights
       โ”œโ”€โ”€ alignment_WFLW_4HG.pth
       โ””โ”€โ”€ detection_Resnet50_Final.pth
โ”œโ”€โ”€ Chinese-LLaMA-2-7B-hf // Linly model weights path
    โ”œโ”€โ”€ config.json
    โ”œโ”€โ”€ generation_config.json
    โ”œโ”€โ”€ pytorch_model-00001-of-00002.bin
    โ”œโ”€โ”€ pytorch_model-00002-of-00002.bin
    โ”œโ”€โ”€ pytorch_model.bin.index.json
    โ”œโ”€โ”€ README.md
    โ”œโ”€โ”€ special_tokens_map.json
    โ”œโ”€โ”€ tokenizer_config.json
    โ””โ”€โ”€ tokenizer.model

Next, launch the app:

python app.py

Users can upload images for the conversation

python app_img.py

Reference

Star History

Star History Chart

About

Digital Avatar Conversational System - Linly-Talker. ๐Ÿ˜„โœจ Linly-Talker is an intelligent AI system that combines large language models (LLMs) with visual models to create a novel human-AI interaction method. ๐Ÿค๐Ÿค– It integrates various technologies like Whisper, Linly, Microsoft Speech Services, and SadTalker talking head generation system. ๐ŸŒŸ๐Ÿ”ฌ


Languages

Language:Python 99.8%Language:Shell 0.1%Language:Jupyter Notebook 0.1%