| import requests |
| import json |
|
|
| messages = [ |
| { |
| "role": "user", |
| "content": [ |
| { |
| "type": "text", |
| "text": "Depending on this image Create tell me a image generation prompt to create this:" |
| }, |
| ] |
| }, |
| ] |
|
|
| model = "deepseek-r1" |
|
|
| url = "https://chipling-api.hf.space/api/v1/text/generate" |
|
|
| payload = { |
| "messages": messages, |
| "model": model, |
| "api_key":"test" |
| } |
|
|
| response = requests.post(url, json=payload, stream=True) |
|
|
| if response.status_code == 200: |
| for line in response.iter_lines(): |
| if line: |
| print(line) |
| decoded_line = line.decode('utf-8') |
| if decoded_line.startswith('data: [DONE]'): |
| break |
| elif decoded_line.startswith('data: '): |
| try: |
| json_data = json.loads(decoded_line[6:]) |
| if json_data["choices"] and "text" in json_data["choices"][0]: |
| print(json_data["choices"][0]["text"], end='') |
| except json.JSONDecodeError: |
| continue |
| else: |
| print(f"Request failed with status code {response.status_code}") |
|
|
|
|
| |
|
|
| |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |