|
|
import os |
|
|
import requests |
|
|
import gradio as gr |
|
|
from src.gradio_demo import SadTalker |
|
|
from huggingface_hub import snapshot_download |
|
|
|
|
|
|
|
|
def download_model(): |
|
|
REPO_ID = 'vinthony/SadTalker-V002rc' |
|
|
snapshot_download(repo_id=REPO_ID, local_dir='./checkpoints', local_dir_use_symlinks=True) |
|
|
|
|
|
download_model() |
|
|
sad_talker = SadTalker(lazy_load=True) |
|
|
|
|
|
|
|
|
|
|
|
def farmer_agent(question): |
|
|
|
|
|
groq_url = "https://api.groq.com/openai/v1/chat/completions" |
|
|
headers = {"Authorization": "Bearer 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"} |
|
|
payload = { |
|
|
"model": "llama-3.1-8b-instant", |
|
|
"messages": [{"role": "system", "content": "You are a village farmer expert. 2 sentences."}, |
|
|
{"role": "user", "content": question}] |
|
|
} |
|
|
resp = requests.post(groq_url, json=payload, headers=headers).json() |
|
|
advice = resp['choices'][0]['message']['content'] |
|
|
|
|
|
|
|
|
source_img = "examples/source_image/full_body_1.png" |
|
|
|
|
|
|
|
|
video_path = sad_talker.test( |
|
|
source_img, |
|
|
advice, |
|
|
'crop', |
|
|
True, |
|
|
False, |
|
|
1, |
|
|
256, |
|
|
0, |
|
|
'facevid2vid', |
|
|
1.0, |
|
|
False, |
|
|
None, |
|
|
'pose', |
|
|
False, |
|
|
5, |
|
|
True |
|
|
) |
|
|
return video_path, advice |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("# 🌾 Farmer GenAI Advisor") |
|
|
with gr.Row(): |
|
|
input_text = gr.Textbox(label="Farmer's Question") |
|
|
output_video = gr.Video(label="Advisor Video") |
|
|
output_text = gr.Textbox(label="Advice Text") |
|
|
|
|
|
btn = gr.Button("Ask the Expert") |
|
|
btn.click(fn=farmer_agent, inputs=input_text, outputs=[output_video, output_text]) |
|
|
|
|
|
demo.launch(server_name="0.0.0.0", server_port=7860) |