Sayiqa commited on
Commit
9db2c3c
·
verified ·
1 Parent(s): 16ab1f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
app.py CHANGED
@@ -240,8 +240,8 @@ text_to_image.enable_attention_slicing()
240
  text_to_image.safety_checker = None
241
  text_to_image.scheduler = DPMSolverMultistepScheduler.from_config(text_to_image.scheduler.config)
242
 
243
- # Load conversational model using text-generation task
244
- chat_pipeline = pipeline("text-generation", model="microsoft/DialoGPT-medium")
245
 
246
  # Preprocess audio file into NumPy array
247
  def preprocess_audio(audio_path):
@@ -274,14 +274,14 @@ def generate_image_from_text(text):
274
  except Exception as e:
275
  return f"Error in image generation: {str(e)}"
276
 
277
- # ChatGPT-like conversational response
278
- def chat_with_gpt(prompt):
279
  try:
280
- # Generate conversational response
281
- response = chat_pipeline(prompt, max_length=100, num_return_sequences=1)
282
- return response[0]["generated_text"]
283
  except Exception as e:
284
- return f"Error in chat response: {str(e)}"
285
 
286
  # Combined processing function
287
  def process_audio_and_generate_results(audio_path):
@@ -335,22 +335,23 @@ voice_to_image_and_chat_iface = gr.Interface(
335
  description="Upload an audio file to transcribe speech to text and generate an image based on the transcription.",
336
  )
337
 
338
- # Gradio interface for ChatGPT-like functionality
339
- chat_iface = gr.Interface(
340
- fn=chat_with_gpt,
341
- inputs=gr.Textbox(label="Enter your prompt for ChatGPT"),
342
- outputs=gr.Textbox(label="ChatGPT Response"),
343
- title="ChatGPT",
344
- description="Chat with GPT-like conversational AI.",
345
  )
346
 
347
  # Combined Gradio app
348
  iface = gr.TabbedInterface(
349
- interface_list=[speech_to_text_iface, voice_to_image_and_chat_iface, chat_iface],
350
- tab_names=["Speech-to-Text", "Voice-to-Image", "ChatGPT"]
351
  )
352
 
353
  # Launch Gradio interface
354
  iface.launch(debug=True, share=True)
355
 
356
 
 
 
240
  text_to_image.safety_checker = None
241
  text_to_image.scheduler = DPMSolverMultistepScheduler.from_config(text_to_image.scheduler.config)
242
 
243
+ # Load question-answering model
244
+ qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
245
 
246
  # Preprocess audio file into NumPy array
247
  def preprocess_audio(audio_path):
 
274
  except Exception as e:
275
  return f"Error in image generation: {str(e)}"
276
 
277
+ # Question answering function
278
+ def answer_question(question):
279
  try:
280
+ context = """Imran Khan is a Pakistani politician, former cricketer, and philanthropist. He is the 22nd Prime Minister of Pakistan, serving from 2018 to 2022. Khan is the founder of the political party Pakistan Tehreek-e-Insaf (PTI). He was one of the most successful cricketers of his time and led Pakistan to victory in the 1992 Cricket World Cup."""
281
+ answer = qa_pipeline(question=question, context=context)
282
+ return answer['answer']
283
  except Exception as e:
284
+ return f"Error in answering question: {str(e)}"
285
 
286
  # Combined processing function
287
  def process_audio_and_generate_results(audio_path):
 
335
  description="Upload an audio file to transcribe speech to text and generate an image based on the transcription.",
336
  )
337
 
338
+ # Gradio interface for Question Answering
339
+ qa_iface = gr.Interface(
340
+ fn=answer_question,
341
+ inputs=gr.Textbox(label="Ask a question"),
342
+ outputs=gr.Textbox(label="Answer"),
343
+ title="Question Answering",
344
+ description="Ask a factual question, and get an answer.",
345
  )
346
 
347
  # Combined Gradio app
348
  iface = gr.TabbedInterface(
349
+ interface_list=[speech_to_text_iface, voice_to_image_and_chat_iface, qa_iface],
350
+ tab_names=["Speech-to-Text", "Voice-to-Image", "Question Answering"]
351
  )
352
 
353
  # Launch Gradio interface
354
  iface.launch(debug=True, share=True)
355
 
356
 
357
+