awacke1 commited on
Commit
19b3cb0
1 Parent(s): 1a9386d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -39
app.py CHANGED
@@ -15,32 +15,24 @@ MODEL = "gpt-4o"
15
  def process_text():
16
  text_input = st.text_input("Enter your text:")
17
  if text_input:
18
- completion = openai.ChatCompletion.create(
19
  model=MODEL,
20
- messages=[
21
- {"role": "system", "content": "You are a helpful assistant. Help me with my math homework!"},
22
- {"role": "user", "content": f"Hello! Could you solve {text_input}?"}
23
- ]
24
  )
25
- st.write("Assistant: " + completion.choices[0].message["content"])
26
 
27
  def process_image(image_input):
28
  if image_input:
29
  base64_image = base64.b64encode(image_input.read()).decode("utf-8")
30
- response = openai.ChatCompletion.create(
31
  model=MODEL,
32
- messages=[
33
- {"role": "system", "content": "You are a helpful assistant that responds in Markdown. Help me with my math homework!"},
34
- {"role": "user", "content": [
35
- {"type": "text", "text": "What's the area of the triangle?"},
36
- {"type": "image_url", "image_url": {
37
- "url": f"data:image/png;base64,{base64_image}"}
38
- }
39
- ]}
40
- ],
41
- temperature=0.0,
42
  )
43
- st.markdown(response.choices[0].message["content"])
44
 
45
  def process_audio(audio_input):
46
  if audio_input:
@@ -48,17 +40,13 @@ def process_audio(audio_input):
48
  model="whisper-1",
49
  file=audio_input,
50
  )
51
- response = openai.ChatCompletion.create(
52
  model=MODEL,
53
- messages=[
54
- {"role": "system", "content": "You are generating a transcript summary. Create a summary of the provided transcription. Respond in Markdown."},
55
- {"role": "user", "content": [
56
- {"type": "text", "text": f"The audio transcription is: {transcription.text}"}
57
- ]},
58
- ],
59
- temperature=0,
60
  )
61
- st.markdown(response.choices[0].message["content"])
62
 
63
  def process_video(video_input):
64
  if video_input:
@@ -67,20 +55,14 @@ def process_video(video_input):
67
  model="whisper-1",
68
  file=open(audio_path, "rb"),
69
  )
70
- response = openai.ChatCompletion.create(
 
71
  model=MODEL,
72
- messages=[
73
- {"role": "system", "content": "You are generating a video summary. Create a summary of the provided video and its transcript. Respond in Markdown"},
74
- {"role": "user", "content": [
75
- "These are the frames from the video.",
76
- *map(lambda x: {"type": "image_url",
77
- "image_url": {"url": f'data:image/jpg;base64,{x}', "detail": "low"}}, base64Frames),
78
- {"type": "text", "text": f"The audio transcription is: {transcription.text}"}
79
- ]},
80
- ],
81
- temperature=0,
82
  )
83
- st.markdown(response.choices[0].message["content"])
84
 
85
  def process_video_frames(video_path, seconds_per_frame=2):
86
  base64Frames = []
 
15
  def process_text():
16
  text_input = st.text_input("Enter your text:")
17
  if text_input:
18
+ response = openai.Completion.create(
19
  model=MODEL,
20
+ prompt=f"You are a helpful assistant. Help me with my math homework! {text_input}",
21
+ max_tokens=100,
22
+ temperature=0.5,
 
23
  )
24
+ st.write("Assistant: " + response.choices[0].text.strip())
25
 
26
  def process_image(image_input):
27
  if image_input:
28
  base64_image = base64.b64encode(image_input.read()).decode("utf-8")
29
+ response = openai.Completion.create(
30
  model=MODEL,
31
+ prompt=f"You are a helpful assistant that responds in Markdown. Help me with my math homework! What's the area of the triangle? [image: data:image/png;base64,{base64_image}]",
32
+ max_tokens=100,
33
+ temperature=0.5,
 
 
 
 
 
 
 
34
  )
35
+ st.markdown(response.choices[0].text.strip())
36
 
37
  def process_audio(audio_input):
38
  if audio_input:
 
40
  model="whisper-1",
41
  file=audio_input,
42
  )
43
+ response = openai.Completion.create(
44
  model=MODEL,
45
+ prompt=f"You are generating a transcript summary. Create a summary of the provided transcription. Respond in Markdown. The audio transcription is: {transcription['text']}",
46
+ max_tokens=100,
47
+ temperature=0.5,
 
 
 
 
48
  )
49
+ st.markdown(response.choices[0].text.strip())
50
 
51
  def process_video(video_input):
52
  if video_input:
 
55
  model="whisper-1",
56
  file=open(audio_path, "rb"),
57
  )
58
+ frames_text = " ".join([f"[image: data:image/jpg;base64,{frame}]" for frame in base64Frames])
59
+ response = openai.Completion.create(
60
  model=MODEL,
61
+ prompt=f"You are generating a video summary. Create a summary of the provided video and its transcript. Respond in Markdown. These are the frames from the video. {frames_text} The audio transcription is: {transcription['text']}",
62
+ max_tokens=500,
63
+ temperature=0.5,
 
 
 
 
 
 
 
64
  )
65
+ st.markdown(response.choices[0].text.strip())
66
 
67
  def process_video_frames(video_path, seconds_per_frame=2):
68
  base64Frames = []