Update app.py
Browse files
app.py
CHANGED
@@ -65,13 +65,38 @@ agent = initialize_agent(
|
|
65 |
)
|
66 |
)
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
import gradio as gr
|
69 |
def segment(image,text):
|
70 |
#pass # Implement your image segmentation model here...
|
71 |
print(image)
|
72 |
image_url = image
|
73 |
-
|
74 |
-
return agent(f"{text}:\n{image_url}").get('output')
|
75 |
|
76 |
demo = gr.Interface(
|
77 |
fn=segment,
|
|
|
65 |
)
|
66 |
)
|
67 |
|
68 |
+
from langchain.chains import LLMChain
|
69 |
+
from langchain.prompts import PromptTemplate
|
70 |
+
def enToChinese(english):
|
71 |
+
#ch = llm_fy("Please translate the following sentence from English to Chinese:"+english)
|
72 |
+
#return ch
|
73 |
+
pp = "Please translate the following sentence from English to Chinese:{english}"
|
74 |
+
prompt = PromptTemplate(
|
75 |
+
input_variables=["english"],
|
76 |
+
template=pp
|
77 |
+
)
|
78 |
+
llchain=LLMChain(llm=llm,prompt=prompt)
|
79 |
+
return llchain.run(english)
|
80 |
+
|
81 |
+
|
82 |
+
def chToEnglish(chinese):
|
83 |
+
#en = llm_fy("Please translate the following sentence from Chinese to English:"+chinese)
|
84 |
+
#return en
|
85 |
+
pp = "Please translate the following sentence from Chinese to English:{chinese}"
|
86 |
+
prompt = PromptTemplate(
|
87 |
+
input_variables=["chinese"],
|
88 |
+
template=pp
|
89 |
+
)
|
90 |
+
llchain=LLMChain(llm=llm,prompt=prompt)
|
91 |
+
return llchain.run(chinese)
|
92 |
+
|
93 |
import gradio as gr
|
94 |
def segment(image,text):
|
95 |
#pass # Implement your image segmentation model here...
|
96 |
print(image)
|
97 |
image_url = image
|
98 |
+
text = chToEnglish(text)
|
99 |
+
return enToChinese(agent(f"{text}:\n{image_url}").get('output'))
|
100 |
|
101 |
demo = gr.Interface(
|
102 |
fn=segment,
|