leadingbridge commited on
Commit
c14ef23
1 Parent(s): 0c6360c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -48,6 +48,21 @@ def chatgpt_clone(input, history):
48
  history.append((input, output))
49
  return history, history
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  # Gradio Output Model
52
  with gr.Blocks() as demo:
53
  gr.Markdown("Choose the Chinese NLP model you want to use from the tabs")
@@ -57,6 +72,11 @@ with gr.Blocks() as demo:
57
  state = gr.State()
58
  submit = gr.Button("SEND")
59
  submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
 
 
 
 
 
60
  with gr.Tab("Sentiment Analysis"):
61
  inputs = gr.Textbox(placeholder="Enter a Chinese positive or negative sentence here")
62
  outputs = gr.Textbox(label="Sentiment Analysis")
@@ -64,4 +84,6 @@ with gr.Blocks() as demo:
64
  proceed_button.click(fn=sentiment_analysis, inputs=inputs, outputs=outputs)
65
 
66
 
 
 
67
  demo.launch(inline=False)
 
48
  history.append((input, output))
49
  return history, history
50
 
51
+
52
+ # Open AI Translation Model
53
+ def translate_to_chinese(text_to_translate):
54
+ response = openai.Completion.create(
55
+ model="text-davinci-003",
56
+ prompt=f"Translate this short sentence into Chinese:\n\n{text_to_translate}\n\n1.",
57
+ temperature=0.3,
58
+ max_tokens=1024,
59
+ top_p=1.0,
60
+ frequency_penalty=0.0,
61
+ presence_penalty=0.0
62
+ )
63
+ return response.choices[0].text.strip()
64
+
65
+
66
  # Gradio Output Model
67
  with gr.Blocks() as demo:
68
  gr.Markdown("Choose the Chinese NLP model you want to use from the tabs")
 
72
  state = gr.State()
73
  submit = gr.Button("SEND")
74
  submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
75
+ with gr.Tab("Translation to Chinese"):
76
+ inputs = gr.Textbox(placeholder="Enter an English sentence to translate to Chinese here.")
77
+ outputs = gr.Textbox(label="Translation Result")
78
+ proceed_button = gr.Button("Translate")
79
+ proceed_button.click(fn=translate_to_chinese, inputs=inputs, outputs=outputs)
80
  with gr.Tab("Sentiment Analysis"):
81
  inputs = gr.Textbox(placeholder="Enter a Chinese positive or negative sentence here")
82
  outputs = gr.Textbox(label="Sentiment Analysis")
 
84
  proceed_button.click(fn=sentiment_analysis, inputs=inputs, outputs=outputs)
85
 
86
 
87
+
88
+
89
  demo.launch(inline=False)