Spaces:
Runtime error
Runtime error
lllchenlll
commited on
Commit
·
8615b96
1
Parent(s):
ace78e8
Add application file
Browse files- app.py +19 -1
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,10 +1,28 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
from sentence_transformers import SentenceTransformer
|
|
|
4 |
|
5 |
|
6 |
def process(api, caption, category, asr, ocr):
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
|
10 |
with gr.Blocks() as demo:
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
3 |
|
4 |
from sentence_transformers import SentenceTransformer
|
5 |
+
from langchain.prompts import PromptTemplate
|
6 |
|
7 |
|
8 |
def process(api, caption, category, asr, ocr):
|
9 |
+
openai.api_key = api
|
10 |
+
preference = "兴趣标签"
|
11 |
+
example = "例如,给定一个视频,它的\"标题\"为\"长安系最便宜的轿车,4W起很多人都看不上它,但我知道车只是代步工具,又需要什么面子呢!\"" \
|
12 |
+
"类别\"为\"汽车\",\"ocr\"为\"长安系最便宜的一款轿车\",\"asr\"为\"我不否认现在的国产和合资还有一定的差距,但确实是他们让" \
|
13 |
+
"我们5万开了MP V8万开上了轿车,10万开张了ICV15万开张了大七座。\",{}生成机器人推断出合理的\"{}\"为\"长安轿车报价、最便宜的" \
|
14 |
+
"长安轿车、新款长安轿车\"。".format(preference, preference),
|
15 |
+
|
16 |
+
prompt = PromptTemplate(
|
17 |
+
input_variables=["preference", "caption", "ocr", "asr", "category", "example"],
|
18 |
+
template="你是一个视频的{preference}生成机器人,根据输入的视频标题、类别、ocr、asr推理出合理的\"{preference}\",以多个多"
|
19 |
+
"于两字的标签形式进行表达,以顿号隔开。{example}那么,给定一个新的视频,它的\"标题\"为\"{caption}\",\"类别\"为"
|
20 |
+
"\"{category}\",\"ocr\"为\"{ocr}\",\"asr\"为\"{asr}\",请推断出该视频的\"{preference}\":"
|
21 |
+
)
|
22 |
+
|
23 |
+
text = prompt.format(preference=preference, caption=caption, category=category, ocr=ocr, asr=asr, example=example)
|
24 |
+
|
25 |
+
return text
|
26 |
|
27 |
|
28 |
with gr.Blocks() as demo:
|
requirements.txt
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
gradio==3.24.1
|
2 |
-
sentence-transformers==2.2.2
|
|
|
|
|
|
1 |
gradio==3.24.1
|
2 |
+
sentence-transformers==2.2.2
|
3 |
+
openai==0.27.4
|
4 |
+
langchain==0.0.133
|