seawolf2357 commited on
Commit
32a70d2
ยท
verified ยท
1 Parent(s): 8335785

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -1,21 +1,21 @@
1
  import gradio as gr
2
  import requests
3
- import spacy
4
  import json
 
5
 
6
  API_URL = "https://api.openai.com/v1/chat/completions"
7
 
8
- # spaCy NLP ๋ชจ๋ธ ๋กœ๋“œ
9
- nlp = spacy.load("en_core_web_sm")
10
 
11
- def extract_keywords(text):
12
- # ํ…์ŠคํŠธ์—์„œ Noun chunks๋ฅผ ์ถ”์ถœํ•˜์—ฌ ํ•ต์‹ฌ ํ‚ค์›Œ๋“œ๋กœ ์‚ฌ์šฉ
13
- doc = nlp(text)
14
- keywords = [chunk.text for chunk in doc.noun_chunks][:3] # ์ƒ์œ„ 3๊ฐœ noun chunks๋ฅผ ํ‚ค์›Œ๋“œ๋กœ ์„ ํƒ
15
- return ", ".join(keywords)
16
 
17
  def predict(inputs, top_p, temperature, openai_api_key):
18
- narration_prompt = f"์•„๋™์šฉ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋™์˜์ƒ์— ์‚ฌ์šฉํ•  ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋ผ. ๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ์ž‘์„ฑํ• ๊ฒƒ. ์ผ์ฒด์˜ ์ง€๋ฌธ์ด๋‚˜ ์ง€์‹œ, ๋ฐฐ๊ฒฝ ์„ค๋ช… ๋“ฑ์„ ๋…ธ์ถœ ํ•˜๊ฑฐ๋‚˜ ์ถœ๋ ฅํ•˜์ง€ ๋ง๊ณ  ๊ธฐ์Šน์ „๊ฒฐ์˜ ๊ตฌ์กฐ๋กœ ๋ชจํ—˜์˜ ์ด์œ /์œ„๊ธฐ/๋„์ „/๋ฌธ์ œํ•ด๊ฒฐ/๊ตํ›ˆ์„ ํฌํ•จํ•˜์—ฌ ์ˆœ์ˆ˜ํ•œ ๋‚˜๋ ˆ์ด์…˜๋งŒ 1์ค„์”ฉ ์ถœ๋ ฅํ•˜์—ฌ ์ตœ๋Œ€ 10์ค„ ์ด๋‚ด๋กœ ์ถœ๋ ฅ. ์ž…๋ ฅ: '{inputs}'"
19
  headers = {
20
  "Content-Type": "application/json",
21
  "Authorization": f"Bearer {openai_api_key}"
@@ -37,10 +37,10 @@ def predict(inputs, top_p, temperature, openai_api_key):
37
  return "Error: Unable to generate response."
38
 
39
  def generate_prompts(script):
40
- # ์Šคํฌ๋ฆฝํŠธ์˜ ๊ฐ ์ค„์—์„œ ํ‚ค์›Œ๋“œ๋ฅผ ์ถ”์ถœํ•˜์—ฌ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
41
  lines = script.split('\n')
42
- prompts = [f"3d style, 4K, like Brad Pitt young boy, {extract_keywords(line)}" for line in lines if line.strip() != '']
43
- return "\n".join(prompts)
44
 
45
  with gr.Blocks() as demo:
46
  gr.Markdown("<h1 align='center'>ํ† ๋ฆฌ์˜ ๋ชจํ—˜: 3D ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ƒ์„ฑ๊ธฐ</h1>")
@@ -50,9 +50,9 @@ with gr.Blocks() as demo:
50
  top_p = gr.Slider(minimum=0, maximum=1.0, value=1.0, step=0.05, label="Top-p (nucleus sampling)")
51
  temperature = gr.Slider(minimum=0, maximum=5.0, value=1.0, step=0.1, label="Temperature")
52
  output = gr.Textbox(label="Generated Script", readonly=True)
53
- prompts_output = gr.TextArea(label="Image Generation Prompts", readonly=True)
54
  submit_button = gr.Button("Generate Script")
55
- prompts_button = gr.Button("Generate Image Prompts")
56
 
57
  submit_button.click(fn=predict, inputs=[inputs, top_p, temperature, openai_api_key], outputs=output)
58
  prompts_button.click(fn=generate_prompts, inputs=[output], outputs=prompts_output)
 
1
  import gradio as gr
2
  import requests
 
3
  import json
4
+ from transformers import pipeline
5
 
6
  API_URL = "https://api.openai.com/v1/chat/completions"
7
 
8
+ # ๋ฒˆ์—ญ ํŒŒ์ดํ”„๋ผ์ธ ์ดˆ๊ธฐํ™”
9
+ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
10
 
11
+ def translate_text(text):
12
+ # ์ž…๋ ฅ๋œ ํ…์ŠคํŠธ๋ฅผ ์˜์–ด๋กœ ๋ฒˆ์—ญ
13
+ translation = translator(text, max_length=512)
14
+ translated_text = translation[0]['translation_text']
15
+ return translated_text
16
 
17
  def predict(inputs, top_p, temperature, openai_api_key):
18
+ narration_prompt = f"์•„๋™์šฉ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋™์˜์ƒ์— ์‚ฌ์šฉํ•  ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋ผ. ๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ์ž‘์„ฑํ• ๊ฒƒ. ์ž…๋ ฅ: '{inputs}'"
19
  headers = {
20
  "Content-Type": "application/json",
21
  "Authorization": f"Bearer {openai_api_key}"
 
37
  return "Error: Unable to generate response."
38
 
39
  def generate_prompts(script):
40
+ # ์Šคํฌ๋ฆฝํŠธ์˜ ๊ฐ ์ค„์„ ์˜์–ด๋กœ ๋ฒˆ์—ญํ•˜์—ฌ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
41
  lines = script.split('\n')
42
+ translated_prompts = [translate_text(line) for line in lines if line.strip() != '']
43
+ return "\n".join(translated_prompts)
44
 
45
  with gr.Blocks() as demo:
46
  gr.Markdown("<h1 align='center'>ํ† ๋ฆฌ์˜ ๋ชจํ—˜: 3D ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ƒ์„ฑ๊ธฐ</h1>")
 
50
  top_p = gr.Slider(minimum=0, maximum=1.0, value=1.0, step=0.05, label="Top-p (nucleus sampling)")
51
  temperature = gr.Slider(minimum=0, maximum=5.0, value=1.0, step=0.1, label="Temperature")
52
  output = gr.Textbox(label="Generated Script", readonly=True)
53
+ prompts_output = gr.TextArea(label="Translated Image Generation Prompts", readonly=True)
54
  submit_button = gr.Button("Generate Script")
55
+ prompts_button = gr.Button("Translate Prompts")
56
 
57
  submit_button.click(fn=predict, inputs=[inputs, top_p, temperature, openai_api_key], outputs=output)
58
  prompts_button.click(fn=generate_prompts, inputs=[output], outputs=prompts_output)