Sameer-Handsome173 commited on
Commit
b4b8f7b
·
verified ·
1 Parent(s): feeb6e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -9
app.py CHANGED
@@ -34,7 +34,6 @@ image_pipeline = pipeline(
34
  def home():
35
  return {"message": "✅ Multimodal RAG API is running successfully!"}
36
 
37
-
38
  # ------------------ 1️⃣ Summarize Text ------------------
39
  @traceable(name="Phi3_Text_Summarization")
40
  @app.post("/summarize_qwen")
@@ -42,7 +41,6 @@ def summarize_text(prompt: str = Form(...)):
42
  result = text_pipeline(prompt, max_new_tokens=200)
43
  return {"response": result[0]["generated_text"]}
44
 
45
-
46
  # ------------------ 2️⃣ Image + Text Summarizer ------------------
47
  @traceable(name="BLIP_Image_Text_Summarization")
48
  @app.post("/summarize_smol")
@@ -55,13 +53,10 @@ async def summarize_smol(text: str = Form(...), image: UploadFile = File(None)):
55
  response = f"{text}\n\n🖼️ Image Summary: {img_result[0]['generated_text']}"
56
  else:
57
  response = text
58
-
59
  return {"response": response}
60
-
61
  except Exception as e:
62
  return {"error": str(e)}
63
 
64
-
65
  # ------------------ 3️⃣ Final Answer (Text + Multiple Images) ------------------
66
  @traceable(name="Final_Multimodal_Answer")
67
  @app.post("/final_answer")
@@ -78,11 +73,9 @@ async def final_answer(
78
  image = Image.open(io.BytesIO(img_bytes)).convert("RGB")
79
  img_result = image_pipeline(image)
80
  combined_context += f"\n\n🖼️ Image Info: {img_result[0]['generated_text']}"
81
-
82
  final_prompt = f"Context: {combined_context}\n\nQuestion: {question}\n\nAnswer:"
83
  result = text_pipeline(final_prompt, max_new_tokens=300)
84
-
85
  return {"response": result[0]["generated_text"]}
86
-
87
  except Exception as e:
88
- return {"error": str(e)}
 
34
  def home():
35
  return {"message": "✅ Multimodal RAG API is running successfully!"}
36
 
 
37
  # ------------------ 1️⃣ Summarize Text ------------------
38
  @traceable(name="Phi3_Text_Summarization")
39
  @app.post("/summarize_qwen")
 
41
  result = text_pipeline(prompt, max_new_tokens=200)
42
  return {"response": result[0]["generated_text"]}
43
 
 
44
  # ------------------ 2️⃣ Image + Text Summarizer ------------------
45
  @traceable(name="BLIP_Image_Text_Summarization")
46
  @app.post("/summarize_smol")
 
53
  response = f"{text}\n\n🖼️ Image Summary: {img_result[0]['generated_text']}"
54
  else:
55
  response = text
 
56
  return {"response": response}
 
57
  except Exception as e:
58
  return {"error": str(e)}
59
 
 
60
  # ------------------ 3️⃣ Final Answer (Text + Multiple Images) ------------------
61
  @traceable(name="Final_Multimodal_Answer")
62
  @app.post("/final_answer")
 
73
  image = Image.open(io.BytesIO(img_bytes)).convert("RGB")
74
  img_result = image_pipeline(image)
75
  combined_context += f"\n\n🖼️ Image Info: {img_result[0]['generated_text']}"
76
+
77
  final_prompt = f"Context: {combined_context}\n\nQuestion: {question}\n\nAnswer:"
78
  result = text_pipeline(final_prompt, max_new_tokens=300)
 
79
  return {"response": result[0]["generated_text"]}
 
80
  except Exception as e:
81
+ return {"error": str(e)}