Imageye commited on
Commit
053db8b
·
verified ·
1 Parent(s): 8e96698

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -4,14 +4,14 @@ import re
4
  import tempfile
5
  import os
6
  import warnings
7
- from groq import Groq
8
  from transformers import pipeline
9
 
10
  # Suppress specific warning
11
  warnings.filterwarnings("ignore", message="FP16 is not supported on CPU; using FP32 instead")
12
 
13
  # Set up Groq client
14
- client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
15
 
16
  # Instantiate Hugging Face pipeline
17
  transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-large-v2")
@@ -38,16 +38,16 @@ def get_transcript(url):
38
  # Function to summarize text using Groq API
39
  def summarize_text(text):
40
  try:
41
- response = client.chat.completions.create(
 
42
  messages=[
43
  {
44
  "role": "user",
45
  "content": f"Summarize the following text:\n\n{text}"
46
  }
47
- ],
48
- model="llama3-8b-8192",
49
  )
50
- summary = response.choices[0].message.content.strip()
51
  return summary
52
  except Exception as e:
53
  return f"Error summarizing text: {e}"
@@ -55,16 +55,16 @@ def summarize_text(text):
55
  # Function to generate quiz questions using Groq API
56
  def generate_quiz_questions(text):
57
  try:
58
- response = client.chat.completions.create(
 
59
  messages=[
60
  {
61
  "role": "user",
62
  "content": f"Generate quiz questions for the following text:\n\n{text}"
63
  }
64
- ],
65
- model="llama3-8b-8192",
66
  )
67
- quiz_questions = response.choices[0].message.content.strip()
68
  return quiz_questions
69
  except Exception as e:
70
  return f"Error generating quiz questions: {e}"
@@ -106,16 +106,16 @@ def parse_quiz_questions(quiz_text):
106
  # Function to generate explanation for quiz answers using Groq API
107
  def generate_explanation(question, correct_answer, user_answer):
108
  try:
109
- response = client.chat.completions.create(
 
110
  messages=[
111
  {
112
  "role": "user",
113
  "content": f"Explain why the correct answer to the following question is '{correct_answer}' and not '{user_answer}':\n\n{question}"
114
  }
115
- ],
116
- model="llama3-8b-8192",
117
  )
118
- explanation = response.choices[0].message.content.strip()
119
  return explanation
120
  except Exception as e:
121
  return f"Error generating explanation: {e}"
 
4
  import tempfile
5
  import os
6
  import warnings
7
+ from groq import GroqClient
8
  from transformers import pipeline
9
 
10
  # Suppress specific warning
11
  warnings.filterwarnings("ignore", message="FP16 is not supported on CPU; using FP32 instead")
12
 
13
  # Set up Groq client
14
+ client = GroqClient(api_key=os.environ.get("GROQ_API_KEY"))
15
 
16
  # Instantiate Hugging Face pipeline
17
  transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-large-v2")
 
38
  # Function to summarize text using Groq API
39
  def summarize_text(text):
40
  try:
41
+ response = client.completions.create(
42
+ model="llama3-8b-8192",
43
  messages=[
44
  {
45
  "role": "user",
46
  "content": f"Summarize the following text:\n\n{text}"
47
  }
48
+ ]
 
49
  )
50
+ summary = response.choices[0].message["content"].strip()
51
  return summary
52
  except Exception as e:
53
  return f"Error summarizing text: {e}"
 
55
  # Function to generate quiz questions using Groq API
56
  def generate_quiz_questions(text):
57
  try:
58
+ response = client.completions.create(
59
+ model="llama3-8b-8192",
60
  messages=[
61
  {
62
  "role": "user",
63
  "content": f"Generate quiz questions for the following text:\n\n{text}"
64
  }
65
+ ]
 
66
  )
67
+ quiz_questions = response.choices[0].message["content"].strip()
68
  return quiz_questions
69
  except Exception as e:
70
  return f"Error generating quiz questions: {e}"
 
106
  # Function to generate explanation for quiz answers using Groq API
107
  def generate_explanation(question, correct_answer, user_answer):
108
  try:
109
+ response = client.completions.create(
110
+ model="llama3-8b-8192",
111
  messages=[
112
  {
113
  "role": "user",
114
  "content": f"Explain why the correct answer to the following question is '{correct_answer}' and not '{user_answer}':\n\n{question}"
115
  }
116
+ ]
 
117
  )
118
+ explanation = response.choices[0].message["content"].strip()
119
  return explanation
120
  except Exception as e:
121
  return f"Error generating explanation: {e}"