Update app.py
Browse files
app.py
CHANGED
@@ -2,14 +2,18 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
import librosa
|
4 |
from transformers import pipeline
|
5 |
-
import torch
|
6 |
from datetime import datetime
|
7 |
import os
|
8 |
import requests
|
9 |
|
|
|
|
|
|
|
|
|
|
|
10 |
# Inference API 설정
|
11 |
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
12 |
-
headers = {"Authorization": "Bearer
|
13 |
|
14 |
# AI 모델 초기화
|
15 |
speech_recognizer = pipeline(
|
@@ -26,27 +30,40 @@ text_analyzer = pipeline(
|
|
26 |
)
|
27 |
korean_sentiment = pipeline(
|
28 |
"text-classification",
|
29 |
-
model="searle-j/korean_sentiment_analysis"
|
30 |
)
|
31 |
|
32 |
def generate_image_from_prompt(prompt):
|
33 |
-
"""
|
|
|
34 |
try:
|
35 |
-
|
36 |
-
"
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
}
|
42 |
-
|
43 |
|
44 |
if response.status_code == 200:
|
|
|
45 |
return response.content
|
46 |
else:
|
|
|
|
|
47 |
return None
|
|
|
48 |
except Exception as e:
|
49 |
-
print(f"Error generating image: {e}")
|
50 |
return None
|
51 |
|
52 |
def create_interface():
|
@@ -283,11 +300,12 @@ def generate_detailed_prompt(text, voice_emotion, text_sentiment, acoustic_featu
|
|
283 |
generate_btn.click(
|
284 |
fn=generate_image_from_prompt,
|
285 |
inputs=[final_prompt],
|
286 |
-
outputs=[result_image]
|
|
|
287 |
)
|
288 |
|
289 |
return app
|
290 |
|
291 |
if __name__ == "__main__":
|
292 |
demo = create_interface()
|
293 |
-
demo.launch()
|
|
|
2 |
import numpy as np
|
3 |
import librosa
|
4 |
from transformers import pipeline
|
|
|
5 |
from datetime import datetime
|
6 |
import os
|
7 |
import requests
|
8 |
|
9 |
+
# 환경변수에서 토큰 가져오기
|
10 |
+
HF_API_TOKEN = os.getenv("HF_API_TOKEN")
|
11 |
+
if not HF_API_TOKEN:
|
12 |
+
raise ValueError("HF_API_TOKEN not found in environment variables")
|
13 |
+
|
14 |
# Inference API 설정
|
15 |
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
16 |
+
headers = {"Authorization": f"Bearer {HF_API_TOKEN}"}
|
17 |
|
18 |
# AI 모델 초기화
|
19 |
speech_recognizer = pipeline(
|
|
|
30 |
)
|
31 |
korean_sentiment = pipeline(
|
32 |
"text-classification",
|
33 |
+
model="searle-j/korean_sentiment_analysis"
|
34 |
)
|
35 |
|
36 |
def generate_image_from_prompt(prompt):
|
37 |
+
"""이미지 생성 함수"""
|
38 |
+
print(f"Generating image with prompt: {prompt}") # 디버깅용
|
39 |
try:
|
40 |
+
if not prompt:
|
41 |
+
print("No prompt provided")
|
42 |
+
return None
|
43 |
+
|
44 |
+
response = requests.post(
|
45 |
+
API_URL,
|
46 |
+
headers=headers,
|
47 |
+
json={
|
48 |
+
"inputs": prompt,
|
49 |
+
"parameters": {
|
50 |
+
"negative_prompt": "ugly, blurry, poor quality, distorted",
|
51 |
+
"num_inference_steps": 30,
|
52 |
+
"guidance_scale": 7.5
|
53 |
+
}
|
54 |
}
|
55 |
+
)
|
56 |
|
57 |
if response.status_code == 200:
|
58 |
+
print("Image generated successfully")
|
59 |
return response.content
|
60 |
else:
|
61 |
+
print(f"Error: {response.status_code}")
|
62 |
+
print(f"Response: {response.text}")
|
63 |
return None
|
64 |
+
|
65 |
except Exception as e:
|
66 |
+
print(f"Error generating image: {str(e)}")
|
67 |
return None
|
68 |
|
69 |
def create_interface():
|
|
|
300 |
generate_btn.click(
|
301 |
fn=generate_image_from_prompt,
|
302 |
inputs=[final_prompt],
|
303 |
+
outputs=[result_image],
|
304 |
+
api_name="generate_image" # API 이름 지정
|
305 |
)
|
306 |
|
307 |
return app
|
308 |
|
309 |
if __name__ == "__main__":
|
310 |
demo = create_interface()
|
311 |
+
demo.launch(debug=True) # 디버그 모드 활성화
|