Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
9 |
-
|
10 |
|
11 |
-
def
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
return
|
16 |
|
17 |
def predict(inputs, top_p, temperature, openai_api_key):
|
18 |
-
narration_prompt = f"์๋์ฉ ์ ๋๋ฉ์ด์
๋์์์ ์ฌ์ฉํ ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํ๋ผ. ๋ฐ๋์ ํ๊ธ๋ก ์์ฑํ ๊ฒ.
|
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 |
-
|
43 |
-
return "\n".join(
|
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("
|
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)
|