ranamhamoud commited on
Commit
2a727f4
·
verified ·
1 Parent(s): 7a430f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -15
app.py CHANGED
@@ -13,11 +13,7 @@ from dotenv import load_dotenv
13
 
14
  load_dotenv()
15
 
16
- openai_key = os.getenv("OPENAI_KEY")
17
-
18
- if openai_key == "":
19
- sys.exit("Please Provide Your OpenAI API Key")
20
-
21
 
22
  def generate_image(text):
23
  try:
@@ -82,12 +78,8 @@ def make_prompt(entry):
82
  # f"TELL A STORY, RELATE TO COMPUTER SCIENCE, INCLUDE ASSESMENTS. MAKE IT REALISTIC AND AROUND 800 WORDS, END THE STORY WITH "THE END.": {entry}"
83
 
84
  def process_text(text):
85
- # First, handle the specific case for [answer:]
86
- # This replaces [answer:] with "Answer:" and keeps the content after it on the same line.
87
  text = re.sub(r'\[answer:\]\s*', 'Answer: ', text)
88
-
89
- # Now, remove all other content within brackets.
90
- # This regex looks for square brackets and any content inside them, excluding those that start with "Answer: " already modified.
91
  text = re.sub(r'\[.*?\](?<!Answer: )', '', text)
92
 
93
  return text
@@ -160,7 +152,7 @@ def generate(
160
  # yield f"Failed to save story: {str(e)}"
161
 
162
 
163
- # Gradio Interface Setup
164
  chat_interface = gr.ChatInterface(
165
  fn=generate,
166
  label=" ",
@@ -171,16 +163,15 @@ chat_interface = gr.ChatInterface(
171
  ["Could you please provide an explanation about the concept of recursion?"],
172
  ["Could you explain what a URL is?"]
173
  ],
174
- theme='shivi/calm_seafoam'
175
  )
176
 
177
  # Gradio Web Interface
178
  with gr.Blocks(css=custom_css,theme='shivi/calm_seafoam',fill_height=True) as demo:
179
- output_image = gr.Image(label="Image Output")
180
- chat_interface.render()
181
  # gr.Markdown(LICENSE)
182
 
183
-
184
  # Main Execution
185
  if __name__ == "__main__":
186
  demo.queue(max_size=20)
 
13
 
14
  load_dotenv()
15
 
16
+ openai_key = os.environ.get(OPENAI_KEY)
 
 
 
 
17
 
18
  def generate_image(text):
19
  try:
 
78
  # f"TELL A STORY, RELATE TO COMPUTER SCIENCE, INCLUDE ASSESMENTS. MAKE IT REALISTIC AND AROUND 800 WORDS, END THE STORY WITH "THE END.": {entry}"
79
 
80
  def process_text(text):
81
+
 
82
  text = re.sub(r'\[answer:\]\s*', 'Answer: ', text)
 
 
 
83
  text = re.sub(r'\[.*?\](?<!Answer: )', '', text)
84
 
85
  return text
 
152
  # yield f"Failed to save story: {str(e)}"
153
 
154
 
155
+ chatbot=gr.Chatbot([(None, ("https://img.freepik.com/free-photo/painting-mountain-lake-with-mountain-background_188544-9126.jpg",))])
156
  chat_interface = gr.ChatInterface(
157
  fn=generate,
158
  label=" ",
 
163
  ["Could you please provide an explanation about the concept of recursion?"],
164
  ["Could you explain what a URL is?"]
165
  ],
166
+ theme='shivi/calm_seafoam',autofocus=True, chatbot=chatbot
167
  )
168
 
169
  # Gradio Web Interface
170
  with gr.Blocks(css=custom_css,theme='shivi/calm_seafoam',fill_height=True) as demo:
171
+ chat_interface.render()
 
172
  # gr.Markdown(LICENSE)
173
 
174
+
175
  # Main Execution
176
  if __name__ == "__main__":
177
  demo.queue(max_size=20)