akhaliq HF Staff commited on
Commit
652b3b8
·
1 Parent(s): ac4aa54

Use direct nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B-NVFP4 model API in generate_prompt

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import json
3
  import gradio as gr
4
  from gradio_client import Client
 
5
 
6
 
7
  def generate_prompt(concept: str) -> str:
@@ -11,7 +12,7 @@ def generate_prompt(concept: str) -> str:
11
  if not concept:
12
  return "a ginger cat wearing a tiny wizard hat reading a spellbook"
13
  try:
14
- client = Client("akhaliq/NVIDIA-Nemotron-3-Ultra-550B-A55B-NVFP4", verbose=False)
15
  system_instruction = (
16
  "You are an expert prompt engineer for text-to-image models. "
17
  "Your task is to take a simple concept and expand it into a detailed, "
@@ -24,13 +25,12 @@ def generate_prompt(concept: str) -> str:
24
  {"role": "system", "content": system_instruction},
25
  {"role": "user", "content": f"Concept: {concept}"}
26
  ]
27
- result = client.predict(
28
- messages_json=json.dumps(messages),
29
  temperature=0.7,
30
- max_tokens=256,
31
- custom_token=None,
32
- api_name="/chat"
33
  )
 
34
  clean_result = str(result).strip()
35
  if clean_result.startswith('"') and clean_result.endswith('"'):
36
  clean_result = clean_result[1:-1]
@@ -38,7 +38,7 @@ def generate_prompt(concept: str) -> str:
38
  clean_result = clean_result[1:-1]
39
  return clean_result
40
  except Exception as e:
41
- print(f"Error calling Nemotron space: {e}")
42
  return f"A detailed, high-quality, professional commercial product photograph of {concept}"
43
 
44
 
 
2
  import json
3
  import gradio as gr
4
  from gradio_client import Client
5
+ from huggingface_hub import InferenceClient
6
 
7
 
8
  def generate_prompt(concept: str) -> str:
 
12
  if not concept:
13
  return "a ginger cat wearing a tiny wizard hat reading a spellbook"
14
  try:
15
+ client = InferenceClient("nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B-NVFP4")
16
  system_instruction = (
17
  "You are an expert prompt engineer for text-to-image models. "
18
  "Your task is to take a simple concept and expand it into a detailed, "
 
25
  {"role": "system", "content": system_instruction},
26
  {"role": "user", "content": f"Concept: {concept}"}
27
  ]
28
+ response = client.chat_completion(
29
+ messages=messages,
30
  temperature=0.7,
31
+ max_tokens=256
 
 
32
  )
33
+ result = response.choices[0].message.content
34
  clean_result = str(result).strip()
35
  if clean_result.startswith('"') and clean_result.endswith('"'):
36
  clean_result = clean_result[1:-1]
 
38
  clean_result = clean_result[1:-1]
39
  return clean_result
40
  except Exception as e:
41
+ print(f"Error calling Nemotron model: {e}")
42
  return f"A detailed, high-quality, professional commercial product photograph of {concept}"
43
 
44