JaweriaGenAI commited on
Commit
721d312
·
verified ·
1 Parent(s): a41aadd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -1,5 +1,5 @@
1
- import gradio as gr
2
  import os
 
3
  import pdfplumber
4
  import docx
5
  import pandas as pd
@@ -9,12 +9,18 @@ import base64
9
  import whisper
10
  from openai import OpenAI
11
 
12
- # Setup GROQ
13
- client = OpenAI(api_key=os.environ["GROQ_API_KEY"], base_url="https://api.groq.com/openai/v1")
14
-
15
  # Load Whisper model
16
  whisper_model = whisper.load_model("base")
17
 
 
 
 
 
 
 
 
 
 
18
  def extract_text_from_file(file):
19
  if file.name.endswith(".pdf"):
20
  with pdfplumber.open(file.name) as pdf:
@@ -51,7 +57,8 @@ def generate_reply(history):
51
  messages=messages,
52
  temperature=0.7
53
  )
54
- return response.choices[0].message.content
 
55
 
56
  def respond(message, history):
57
  reply = generate_reply(history + [[message, ""]])
@@ -75,7 +82,7 @@ with gr.Blocks(css="body { background-color: white; color: black }") as demo:
75
  chatbot = gr.Chatbot(label="Chat", elem_id="chatbox", height=450, type="messages")
76
 
77
  with gr.Row():
78
- txt = gr.Textbox(placeholder="Type your message or review the file/audio content here", scale=5, show_label=False)
79
  send_btn = gr.Button("Send", scale=1)
80
 
81
  with gr.Row():
@@ -84,10 +91,7 @@ with gr.Blocks(css="body { background-color: white; color: black }") as demo:
84
 
85
  history = gr.State([])
86
 
87
- # Message only sent when Send is clicked
88
  send_btn.click(respond, [txt, history], [chatbot, txt])
89
-
90
- # File and audio just modify the message box
91
  upload_btn.change(handle_file_upload, [upload_btn, txt], txt)
92
  audio_in.change(handle_audio_upload, [audio_in, txt], txt)
93
 
 
 
1
  import os
2
+ import gradio as gr
3
  import pdfplumber
4
  import docx
5
  import pandas as pd
 
9
  import whisper
10
  from openai import OpenAI
11
 
 
 
 
12
  # Load Whisper model
13
  whisper_model = whisper.load_model("base")
14
 
15
+ # Load Groq API key
16
+ GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
17
+
18
+ # Initialize OpenAI client with Groq base URL
19
+ client = OpenAI(
20
+ api_key=GROQ_API_KEY,
21
+ base_url="https://api.groq.com/openai/v1"
22
+ )
23
+
24
  def extract_text_from_file(file):
25
  if file.name.endswith(".pdf"):
26
  with pdfplumber.open(file.name) as pdf:
 
57
  messages=messages,
58
  temperature=0.7
59
  )
60
+ reply = response.choices[0].message.content
61
+ return reply
62
 
63
  def respond(message, history):
64
  reply = generate_reply(history + [[message, ""]])
 
82
  chatbot = gr.Chatbot(label="Chat", elem_id="chatbox", height=450, type="messages")
83
 
84
  with gr.Row():
85
+ txt = gr.Textbox(placeholder="Type a message or edit transcribed/file content here...", scale=5, show_label=False)
86
  send_btn = gr.Button("Send", scale=1)
87
 
88
  with gr.Row():
 
91
 
92
  history = gr.State([])
93
 
 
94
  send_btn.click(respond, [txt, history], [chatbot, txt])
 
 
95
  upload_btn.change(handle_file_upload, [upload_btn, txt], txt)
96
  audio_in.change(handle_audio_upload, [audio_in, txt], txt)
97