Spaces:
Configuration error
Configuration error
Tidy
Browse files
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title: Ethan Mollick
|
3 |
emoji: 🏢
|
4 |
colorFrom: purple
|
5 |
colorTo: green
|
|
|
1 |
---
|
2 |
+
title: Ethan Mollick
|
3 |
emoji: 🏢
|
4 |
colorFrom: purple
|
5 |
colorTo: green
|
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import os
|
2 |
-
import random
|
3 |
import re
|
4 |
import gradio as gr
|
5 |
import openai
|
@@ -23,7 +22,6 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
23 |
|
24 |
def ai_complete(messages):
|
25 |
response = openai.ChatCompletion.create(
|
26 |
-
#model = "gpt-3.5-turbo",
|
27 |
model = "gpt-4",
|
28 |
messages = messages,
|
29 |
temperature=0.9,
|
@@ -35,14 +33,10 @@ def ai_complete(messages):
|
|
35 |
|
36 |
def process_message(msg, history, role = "user"):
|
37 |
history = history or [{"role": "system", "content": system_prompt}]
|
38 |
-
|
39 |
history.append({"role":role, "content":msg})
|
40 |
-
|
41 |
output = ai_complete(history)
|
42 |
history.append({"role": output.role, "content": output.content})
|
43 |
-
|
44 |
parsed_history, feedback, plan, grade = parse_history(history)
|
45 |
-
|
46 |
return gr.update(value=""), parsed_history, feedback, plan, grade, history
|
47 |
|
48 |
def parse_history(history):
|
@@ -78,10 +72,6 @@ def parse_history(history):
|
|
78 |
return tuples, ai_feedback, ai_plan, ai_grade
|
79 |
|
80 |
def find_tag_content(content, tag1, tag2):
|
81 |
-
tag1 = tag1.replace('[', '\[')
|
82 |
-
tag1 = tag1.replace(']', '\]')
|
83 |
-
tag2 = tag2.replace('[', '\[')
|
84 |
-
tag2 = tag2.replace(']', '\]')
|
85 |
result = re.search(tag1 + '(.*)' + tag2, content, re.DOTALL)
|
86 |
if result: return result.group(1).strip()
|
87 |
return ""
|
@@ -90,21 +80,14 @@ def set_visible_if_interesting(component: gr.Textbox):
|
|
90 |
return gr.update(visible=(component != ""))
|
91 |
|
92 |
with gr.Blocks(theme=gr.themes.Soft(), css="main.css", title="Demo") as block:
|
93 |
-
|
94 |
-
#gr.Markdown("""<h1><center>Demo</center></h1>""")
|
95 |
-
|
96 |
state = gr.State()
|
97 |
chatbot = gr.Chatbot(label="AI-VC", elem_id="chatbot")
|
98 |
-
message = gr.Textbox(label="User", elem_id="user_input")
|
99 |
-
|
100 |
feedback = gr.Textbox(label="Feedback", visible=False, interactive=False, lines=4)
|
101 |
plan = gr.Textbox(label="Plan", visible=False, interactive=False, lines=3)
|
102 |
grade = gr.Textbox(label="Grade", visible=False, interactive=False, lines=1)
|
103 |
-
|
104 |
feedback.change(set_visible_if_interesting, feedback, feedback)
|
105 |
plan.change(set_visible_if_interesting, plan, plan)
|
106 |
grade.change(set_visible_if_interesting, grade, grade)
|
107 |
-
|
108 |
message.submit(process_message, inputs=[message, state], outputs=[message, chatbot, feedback, plan, grade, state])
|
109 |
-
|
110 |
block.launch(share=False)
|
|
|
1 |
import os
|
|
|
2 |
import re
|
3 |
import gradio as gr
|
4 |
import openai
|
|
|
22 |
|
23 |
def ai_complete(messages):
|
24 |
response = openai.ChatCompletion.create(
|
|
|
25 |
model = "gpt-4",
|
26 |
messages = messages,
|
27 |
temperature=0.9,
|
|
|
33 |
|
34 |
def process_message(msg, history, role = "user"):
|
35 |
history = history or [{"role": "system", "content": system_prompt}]
|
|
|
36 |
history.append({"role":role, "content":msg})
|
|
|
37 |
output = ai_complete(history)
|
38 |
history.append({"role": output.role, "content": output.content})
|
|
|
39 |
parsed_history, feedback, plan, grade = parse_history(history)
|
|
|
40 |
return gr.update(value=""), parsed_history, feedback, plan, grade, history
|
41 |
|
42 |
def parse_history(history):
|
|
|
72 |
return tuples, ai_feedback, ai_plan, ai_grade
|
73 |
|
74 |
def find_tag_content(content, tag1, tag2):
|
|
|
|
|
|
|
|
|
75 |
result = re.search(tag1 + '(.*)' + tag2, content, re.DOTALL)
|
76 |
if result: return result.group(1).strip()
|
77 |
return ""
|
|
|
80 |
return gr.update(visible=(component != ""))
|
81 |
|
82 |
with gr.Blocks(theme=gr.themes.Soft(), css="main.css", title="Demo") as block:
|
|
|
|
|
|
|
83 |
state = gr.State()
|
84 |
chatbot = gr.Chatbot(label="AI-VC", elem_id="chatbot")
|
85 |
+
message = gr.Textbox(label="User", elem_id="user_input")
|
|
|
86 |
feedback = gr.Textbox(label="Feedback", visible=False, interactive=False, lines=4)
|
87 |
plan = gr.Textbox(label="Plan", visible=False, interactive=False, lines=3)
|
88 |
grade = gr.Textbox(label="Grade", visible=False, interactive=False, lines=1)
|
|
|
89 |
feedback.change(set_visible_if_interesting, feedback, feedback)
|
90 |
plan.change(set_visible_if_interesting, plan, plan)
|
91 |
grade.change(set_visible_if_interesting, grade, grade)
|
|
|
92 |
message.submit(process_message, inputs=[message, state], outputs=[message, chatbot, feedback, plan, grade, state])
|
|
|
93 |
block.launch(share=False)
|