marcosremar2 commited on
Commit
218771e
·
1 Parent(s): 70f3914
Files changed (2) hide show
  1. test.mp3 +0 -0
  2. test_llama_omni_api.py +84 -0
test.mp3 ADDED
Binary file (13.5 kB). View file
 
test_llama_omni_api.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test script for LLaMA-Omni API on Hugging Face Spaces.
4
+ This script sends a text message to the LLaMA-Omni2 API and saves the response.
5
+ """
6
+
7
+ import os
8
+ import time
9
+ from pathlib import Path
10
+ from gradio_client import Client
11
+
12
+ # API endpoint
13
+ API_URL = "https://marcosremar2-llama-omni.hf.space"
14
+
15
+ # Input and output paths
16
+ INPUT_AUDIO_PATH = "/Users/marcos/Documents/projects/test/whisper-realtime/llama-omni/llama-omni/test.mp3"
17
+ OUTPUT_DIR = "./output"
18
+ OUTPUT_TEXT_PATH = os.path.join(OUTPUT_DIR, f"response_{int(time.time())}.txt")
19
+
20
+ def main():
21
+ """Main function to test the LLaMA-Omni API"""
22
+ # Ensure output directory exists
23
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
24
+
25
+ print(f"Audio file path: {INPUT_AUDIO_PATH}")
26
+ print(f"API URL: {API_URL}")
27
+
28
+ try:
29
+ # Connect to the Gradio app with increased timeout
30
+ client = Client(
31
+ API_URL,
32
+ httpx_kwargs={"timeout": 300.0} # Increase timeout to 5 minutes
33
+ )
34
+
35
+ print("Connected to API successfully")
36
+
37
+ # Inspect the API endpoints
38
+ print("Available API endpoints:")
39
+ client.view_api()
40
+
41
+ # Since this is a text-based model (LLaMA-Omni2), we'll send a text prompt
42
+ # The audio file can't be directly processed by this API
43
+ print("\nUsing the text generation endpoint (/lambda_1)...")
44
+
45
+ # Create a text prompt describing the audio
46
+ prompt = """This is a test of the LLaMA-Omni2 API.
47
+ Please respond with a sample of what you can do as an AI assistant."""
48
+
49
+ # Submit the text to the API
50
+ print(f"Sending text prompt: '{prompt[:50]}...'")
51
+ job = client.submit(
52
+ prompt,
53
+ "LLaMA-Omni2-7B-Bilingual",
54
+ api_name="/lambda_1"
55
+ )
56
+
57
+ print("Job submitted, waiting for response...")
58
+ result = job.result()
59
+ print(f"Response received (length: {len(str(result))} characters)")
60
+
61
+ # Save the text result
62
+ with open(OUTPUT_TEXT_PATH, "w") as f:
63
+ f.write(str(result))
64
+
65
+ print(f"Text response saved to: {OUTPUT_TEXT_PATH}")
66
+
67
+ # Also try the model info endpoint
68
+ try:
69
+ print("\nQuerying model information...")
70
+ model_info = client.submit(api_name="/lambda").result()
71
+ print(f"Model info: {model_info}")
72
+ except Exception as model_error:
73
+ print(f"Error getting model info: {str(model_error)}")
74
+
75
+ except Exception as e:
76
+ print(f"Error during API request: {str(e)}")
77
+ print("This could be because the Space is currently sleeping and needs time to wake up.")
78
+ print("Try accessing the Space directly in a browser first: " + API_URL)
79
+ print("\nNote: This API appears to be a text-only LLaMA model and does not directly process audio files.")
80
+ print("To work with audio, you would need to first transcribe the audio using a service like Whisper,")
81
+ print("then send the transcribed text to this API.")
82
+
83
+ if __name__ == "__main__":
84
+ main()