whyumesh commited on
Commit
aac82e3
·
verified ·
1 Parent(s): 108b366

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -32,6 +32,21 @@ SYSTEM_PROMPT = """You are an AI assistant specialized in analyzing images and v
32
 
33
  Always strive for accuracy in code extraction, as the user may need to directly use or analyze the extracted code."""
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  @spaces.GPU
37
  def process_image(image, prompt):
@@ -127,20 +142,6 @@ def process_video(video, prompt, max_frames=16, frame_interval=30, max_resolutio
127
 
128
  return output_text[0]
129
 
130
- @spaces.GPU
131
- def process_content(content, prompt):
132
- if content is None:
133
- return "Please upload an image or video file of a code editor."
134
-
135
- full_prompt = f"{SYSTEM_PROMPT}\n\nUser request: {prompt}"
136
-
137
- if content.name.lower().endswith(('.png', '.jpg', '.jpeg')):
138
- return process_image(Image.open(content.name), full_prompt)
139
- elif content.name.lower().endswith(('.mp4', '.avi', '.mov')):
140
- return process_video(content, full_prompt)
141
- else:
142
- return "Unsupported file type. Please provide an image or video file of a code editor."
143
-
144
  # Predefined prompts
145
  PREDEFINED_PROMPTS = [
146
  "Extract all visible code from this IDE screenshot.",
 
32
 
33
  Always strive for accuracy in code extraction, as the user may need to directly use or analyze the extracted code."""
34
 
35
+ @spaces.GPU
36
+ def process_content(content, predefined_prompt, custom_prompt):
37
+ if content is None:
38
+ return "Please upload an image or video file of a code editor."
39
+
40
+ # Combine predefined and custom prompts
41
+ user_prompt = predefined_prompt if predefined_prompt else custom_prompt
42
+ full_prompt = f"{SYSTEM_PROMPT}\n\nUser request: {user_prompt}"
43
+
44
+ if content.name.lower().endswith(('.png', '.jpg', '.jpeg')):
45
+ return process_image(Image.open(content.name), full_prompt)
46
+ elif content.name.lower().endswith(('.mp4', '.avi', '.mov')):
47
+ return process_video(content, full_prompt)
48
+ else:
49
+ return "Unsupported file type. Please provide an image or video file of a code editor."
50
 
51
  @spaces.GPU
52
  def process_image(image, prompt):
 
142
 
143
  return output_text[0]
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  # Predefined prompts
146
  PREDEFINED_PROMPTS = [
147
  "Extract all visible code from this IDE screenshot.",