jvictoria commited on
Commit
61f7b64
1 Parent(s): 7192ae9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -48
app.py CHANGED
@@ -1,51 +1,11 @@
1
- import openai
2
- import gradio
3
- import os
4
- import re
5
 
6
- openai.api_key = os.environ.get("API_TOKEN")
 
7
 
8
- messages = [{"role": "system", "content": "You are an education expert who can correct essays. You are bilingual in English and Japanese"}]
 
 
9
 
10
- MAX_TOKENS = 4096
11
- MAX_HISTORY = 1
12
-
13
- def CustomChatGPT(user_input):
14
- global messages
15
- essay_keywords = ["essay", "エッセイ", "論文"]
16
- action_keywords = ["write", "make", "create", "生成", "作成", "書く"]
17
-
18
- if any(re.search(f"{action_kw}.*{essay_kw}", user_input.lower()) for action_kw in action_keywords for essay_kw in essay_keywords):
19
- return "I'm sorry, I cannot write an essay for you."
20
-
21
- # Clear the messages list before adding new messages
22
- messages = [{"role": "system", "content": "You are an education expert who can correct essays. You are bilingual in English and Japanese"}]
23
-
24
- user_message = {"role": "user", "content": f"Step 1, find make grammar and spelling and corrections. Step 2, show the corrected version. Step 3, Explain in detail all the errors from what I originally wrote. Put each explanation in a bullet point: [{user_input}]"}
25
-
26
- messages.append(user_message)
27
-
28
- while True:
29
- response = openai.ChatCompletion.create(
30
- model="gpt-3.5-turbo",
31
- messages=messages
32
- )
33
-
34
- total_tokens = response['usage']['total_tokens']
35
- if total_tokens < MAX_TOKENS:
36
- break
37
-
38
- ChatGPT_reply = response["choices"][0]["message"]["content"]
39
- messages.append({"role": "assistant", "content": ChatGPT_reply})
40
-
41
- return ChatGPT_reply
42
-
43
- # Add text instructions on top of the input and output boxes
44
- input_text = "ここに訂正してほしい英語の作文を置いてください。そして「Submit」を押してください:"
45
- output_text = "訂正と説明はここに表示されます:"
46
- instructions = "このアプリケーションは、文法と綴りをチェックするために使用できます。アプリは、修正した作文を提供し、それに続いて修正の説明を示します。アプリは、1つのパラグラフずつ入力する場合に最適に機能します。例えば、3つのパラグラフから成る作文をチェックしたい場合は、それぞれのパラグラフを「Submit」してください。つまり、プログラムを3回実行し、各パラグラフごとに1回ずつ実行してください。"
47
-
48
- # Modify the Gradio interface to include the text instructions and image
49
- demo = gradio.Interface(fn=CustomChatGPT, inputs=gradio.inputs.Textbox(lines=5, label=input_text), outputs=gradio.outputs.Textbox(label=output_text), title="Teacher Jihan's Checking Assistant", description=instructions)
50
-
51
- demo.launch(share=False, debug=True)
 
1
+ import gradio as gr
2
+ from transformers import pipeline
 
 
3
 
4
+ def huggingface_model(dummy):
5
+ return "Hello"
6
 
7
+ iface = gr.Interface(fn=huggingface_model,
8
+ inputs=gr.inputs.Text(),
9
+ outputs='text')
10
 
11
+ iface.launch()