Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,31 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from langchain.llms import HuggingFaceHub
|
4 |
-
from langchain.prompts import PromptTemplate
|
5 |
-
from langchain.chains import LLMChain
|
6 |
|
7 |
model_repo = os.getenv('HF_MODEL_REPO')
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
|
13 |
|
14 |
model_kwargs={
|
15 |
-
"max_new_tokens":2048,
|
16 |
-
"temperature":0.
|
17 |
-
"
|
|
|
18 |
}
|
19 |
|
20 |
llm = HuggingFaceHub(repo_id=model_repo, task="text-generation", model_kwargs=model_kwargs)
|
21 |
-
chain = LLMChain(prompt=prompt, llm=llm)
|
22 |
|
23 |
def translation(source, target, text):
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
gr.Interface(translation, inputs=["text","text","text"], outputs="text").launch()
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from langchain.llms import HuggingFaceHub
|
|
|
|
|
4 |
|
5 |
model_repo = os.getenv('HF_MODEL_REPO')
|
6 |
+
template = """[INST]<<SYS>>I want you to be a translator. You do translate {source} texts in the context into {target} then you return to me the whole translated context AND DO NOTHING ELSE.<</SYS>>
|
7 |
+
Begin of the context:
|
8 |
+
{query}
|
9 |
+
End of the context.[/INST]
|
10 |
+
{target} translation of the context:
|
11 |
|
12 |
+
"""
|
13 |
|
14 |
model_kwargs={
|
15 |
+
"max_new_tokens":2048,
|
16 |
+
"temperature": 0.01,
|
17 |
+
"truncate": 4096,
|
18 |
+
"stop" : ["</s>","<|endoftext|>","<|end|>"],
|
19 |
}
|
20 |
|
21 |
llm = HuggingFaceHub(repo_id=model_repo, task="text-generation", model_kwargs=model_kwargs)
|
|
|
22 |
|
23 |
def translation(source, target, text):
|
24 |
+
input_prompt = template.replace("{source}", source)
|
25 |
+
input_prompt = input_prompt.replace("{target}", target)
|
26 |
+
input_prompt = input_prompt.replace("{query}", text)
|
27 |
+
print(input_prompt)
|
28 |
+
response=llm(input_prompt)
|
29 |
+
return response
|
30 |
|
31 |
gr.Interface(translation, inputs=["text","text","text"], outputs="text").launch()
|