Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 244 |
-
|
| 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 |
-
#
|
| 278 |
-
def
|
| 279 |
try:
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
return
|
| 283 |
except Exception as e:
|
| 284 |
-
return f"Error in
|
| 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
|
| 339 |
-
|
| 340 |
-
fn=
|
| 341 |
-
inputs=gr.Textbox(label="
|
| 342 |
-
outputs=gr.Textbox(label="
|
| 343 |
-
title="
|
| 344 |
-
description="
|
| 345 |
)
|
| 346 |
|
| 347 |
# Combined Gradio app
|
| 348 |
iface = gr.TabbedInterface(
|
| 349 |
-
interface_list=[speech_to_text_iface, voice_to_image_and_chat_iface,
|
| 350 |
-
tab_names=["Speech-to-Text", "Voice-to-Image", "
|
| 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 |
+
|