leadingbridge commited on
Commit
8151f8b
1 Parent(s): c14ef23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -7
app.py CHANGED
@@ -49,7 +49,7 @@ def chatgpt_clone(input, history):
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",
@@ -62,6 +62,20 @@ def translate_to_chinese(text_to_translate):
62
  )
63
  return response.choices[0].text.strip()
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  # Gradio Output Model
67
  with gr.Blocks() as demo:
@@ -72,17 +86,21 @@ with gr.Blocks() as demo:
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")
83
  proceed_button = gr.Button("proceed")
84
  proceed_button.click(fn=sentiment_analysis, inputs=inputs, outputs=outputs)
85
-
 
 
 
 
 
 
 
 
 
86
 
87
 
88
 
 
49
  return history, history
50
 
51
 
52
+ # Open AI Chinese Translation Model
53
  def translate_to_chinese(text_to_translate):
54
  response = openai.Completion.create(
55
  model="text-davinci-003",
 
62
  )
63
  return response.choices[0].text.strip()
64
 
65
+ # Open AI English Translation Model
66
+ def translate_to_english(text_to_translate):
67
+ response = openai.Completion.create(
68
+ model="text-davinci-003",
69
+ prompt=f"Translate this short sentence into English:\n\n{text_to_translate}\n\n1.",
70
+ temperature=0.3,
71
+ max_tokens=1024,
72
+ top_p=1.0,
73
+ frequency_penalty=0.0,
74
+ presence_penalty=0.0
75
+ )
76
+ return response.choices[0].text.strip()
77
+
78
+
79
 
80
  # Gradio Output Model
81
  with gr.Blocks() as demo:
 
86
  state = gr.State()
87
  submit = gr.Button("SEND")
88
  submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot, state])
 
 
 
 
 
89
  with gr.Tab("Sentiment Analysis"):
90
  inputs = gr.Textbox(placeholder="Enter a Chinese positive or negative sentence here")
91
  outputs = gr.Textbox(label="Sentiment Analysis")
92
  proceed_button = gr.Button("proceed")
93
  proceed_button.click(fn=sentiment_analysis, inputs=inputs, outputs=outputs)
94
+ with gr.Tab("Translation to Chinese"):
95
+ inputs = gr.Textbox(placeholder="Enter a short English sentence to translate to Chinese here.")
96
+ outputs = gr.Textbox(label="Translation Result")
97
+ proceed_button = gr.Button("Translate")
98
+ proceed_button.click(fn=translate_to_chinese, inputs=inputs, outputs=outputs)
99
+ with gr.Tab("Translation to English"):
100
+ inputs = gr.Textbox(placeholder="Enter a Short sentence to translate to English here.")
101
+ outputs = gr.Textbox(label="Translation Result")
102
+ proceed_button = gr.Button("Translate")
103
+ proceed_button.click(fn=translate_to_chinese, inputs=inputs, outputs=outputs)
104
 
105
 
106