openfree commited on
Commit
363a5a7
·
verified ·
1 Parent(s): 910d23a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -16
app.py CHANGED
@@ -18,17 +18,18 @@ from transformers import pipeline
18
  from gradio_imageslider import ImageSlider
19
  import numpy as np
20
  import warnings
21
- from huggingface_hub import InferenceClient
 
 
22
 
23
  huggingface_token = os.getenv("HF_TOKEN")
24
 
25
 
26
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device="cpu")
27
 
28
- # Hugging Face 클라이언트 초기화
29
- client = InferenceClient(
30
- model="CohereForAI/c4ai-command-r-plus-08-2024",
31
- token=huggingface_token
32
  )
33
 
34
  def augment_prompt(prompt):
@@ -38,21 +39,28 @@ def augment_prompt(prompt):
38
 
39
  system_prompt = """You are an expert at writing detailed image generation prompts.
40
  Enhance the given prompt by adding more descriptive details, artistic style, and technical aspects
41
- that would help in generating better images. Keep the core meaning but make it more comprehensive."""
 
42
 
43
- full_prompt = f"{system_prompt}\nOriginal prompt: {prompt}\nEnhanced prompt:"
44
-
45
- # 클라이언트 인퍼런스 방식으로 호출
46
- response = client.text_generation(
47
- full_prompt,
48
- max_new_tokens=300,
49
  temperature=0.7,
50
- top_p=0.95,
51
- repetition_penalty=1.1,
52
- do_sample=True
 
 
 
 
 
 
 
53
  )
54
 
55
- enhanced_prompt = response.strip()
 
 
56
  return enhanced_prompt
57
  except Exception as e:
58
  print(f"Error in prompt augmentation: {str(e)}")
 
18
  from gradio_imageslider import ImageSlider
19
  import numpy as np
20
  import warnings
21
+ import anthropic # 줄 추가
22
+
23
+
24
 
25
  huggingface_token = os.getenv("HF_TOKEN")
26
 
27
 
28
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device="cpu")
29
 
30
+ # Claude 클라이언트 초기화로 대체
31
+ claude_client = anthropic.Anthropic(
32
+ api_key=os.getenv("CLAUDE_TOKEN")
 
33
  )
34
 
35
  def augment_prompt(prompt):
 
39
 
40
  system_prompt = """You are an expert at writing detailed image generation prompts.
41
  Enhance the given prompt by adding more descriptive details, artistic style, and technical aspects
42
+ that would help in generating better images. Keep the core meaning but make it more comprehensive.
43
+ Focus on visual details and artistic elements that can be represented in an image."""
44
 
45
+ message = claude_client.messages.create(
46
+ model="claude-3-sonnet-20240229",
47
+ max_tokens=300,
 
 
 
48
  temperature=0.7,
49
+ messages=[
50
+ {
51
+ "role": "system",
52
+ "content": system_prompt
53
+ },
54
+ {
55
+ "role": "user",
56
+ "content": f"Original prompt: {prompt}\nPlease enhance this prompt for image generation."
57
+ }
58
+ ]
59
  )
60
 
61
+ enhanced_prompt = message.content[0].text.strip()
62
+ print(f"Original prompt: {prompt}")
63
+ print(f"Enhanced prompt: {enhanced_prompt}")
64
  return enhanced_prompt
65
  except Exception as e:
66
  print(f"Error in prompt augmentation: {str(e)}")