laichai commited on
Commit
1d7d721
·
verified ·
1 Parent(s): 7b4601a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -17
app.py CHANGED
@@ -499,31 +499,81 @@ with st.sidebar:
499
 
500
  st.divider()
501
 
502
- # Image Analysis Settings
503
  st.header("🖼️ Image Analysis")
504
 
505
  image_analysis_mode = st.radio(
506
- "Analysis Method:",
507
- ["DashScope API", "Basic Analysis"],
508
  index=0,
509
- help="DashScope: Advanced AI analysis. Basic: Simple image info."
510
  )
511
 
512
- if image_analysis_mode == "DashScope API":
513
- # Get API key from secrets or env
514
- dashscope_key = None
515
- if hasattr(st, 'secrets') and "DASHSCOPE_API_KEY" in st.secrets:
516
- dashscope_key = st.secrets["DASHSCOPE_API_KEY"]
517
- st.success(" DashScope API configured")
518
- elif "DASHSCOPE_API_KEY" in os.environ:
519
- dashscope_key = os.environ["DASHSCOPE_API_KEY"]
520
- st.success("✓ DashScope API configured")
521
  else:
522
- st.warning("Add DASHSCOPE_API_KEY to secrets")
523
- st.info("Get free credits: dashscope.aliyun.com")
524
- else:
525
- st.info("Basic image analysis mode")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
527
  #st.divider()
528
 
529
  # Media Input
 
499
 
500
  st.divider()
501
 
502
+ # Image Analysis Settings - INTERNATIONAL VERSION
503
  st.header("🖼️ Image Analysis")
504
 
505
  image_analysis_mode = st.radio(
506
+ "Analysis Service:",
507
+ ["Hugging Face", "Together.ai", "OpenRouter", "Basic"],
508
  index=0,
509
+ help="Choose image analysis service"
510
  )
511
 
512
+ if image_analysis_mode == "Hugging Face":
513
+ hf_token = None
514
+ if hasattr(st, 'secrets') and "HF_TOKEN" in st.secrets:
515
+ hf_token = st.secrets["HF_TOKEN"]
516
+ st.success("✓ Hugging Face Token configured")
517
+ elif "HF_TOKEN" in os.environ:
518
+ hf_token = os.environ["HF_TOKEN"]
519
+ st.success("✓ Hugging Face Token configured")
 
520
  else:
521
+ st.warning("Add HF_TOKEN to secrets")
522
+ st.info("Get token: huggingface.co/settings/tokens")
523
+
524
+ elif image_analysis_mode == "Together.ai":
525
+ together_key = None
526
+ if hasattr(st, 'secrets') and "TOGETHER_API_KEY" in st.secrets:
527
+ together_key = st.secrets["TOGETHER_API_KEY"]
528
+ st.success("✓ Together.ai API configured")
529
+ elif "TOGETHER_API_KEY" in os.environ:
530
+ together_key = os.environ["TOGETHER_API_KEY"]
531
+ st.success("✓ Together.ai API configured")
532
+ else:
533
+ st.warning("Add TOGETHER_API_KEY to secrets")
534
+ st.info("Get key: together.ai (free credits available)")
535
+
536
+ elif image_analysis_mode == "OpenRouter":
537
+ openrouter_key = None
538
+ if hasattr(st, 'secrets') and "OPENROUTER_API_KEY" in st.secrets:
539
+ openrouter_key = st.secrets["OPENROUTER_API_KEY"]
540
+ st.success("✓ OpenRouter API configured")
541
+ elif "OPENROUTER_API_KEY" in os.environ:
542
+ openrouter_key = os.environ["OPENROUTER_API_KEY"]
543
+ st.success("✓ OpenRouter API configured")
544
+ else:
545
+ st.warning("Add OPENROUTER_API_KEY to secrets")
546
+ st.info("Get key: openrouter.ai (free credits available)")
547
 
548
+ else: # Basic
549
+ st.info("Basic image analysis mode")
550
+ # Analyze immediately based on selected mode
551
+ with st.spinner("Analyzing image..."):
552
+ if image_analysis_mode == "Hugging Face" and hf_token:
553
+ image_analysis = analyze_image_with_huggingface(
554
+ image,
555
+ "Analyze this physics image. What concepts, diagrams, or equations do you see?",
556
+ hf_token
557
+ )
558
+ elif image_analysis_mode == "Together.ai" and together_key:
559
+ image_analysis = analyze_image_with_togetherai(
560
+ image,
561
+ "Analyze this physics image. What concepts, diagrams, or equations do you see?",
562
+ together_key
563
+ )
564
+ elif image_analysis_mode == "OpenRouter" and openrouter_key:
565
+ image_analysis = analyze_image_with_openrouter(
566
+ image,
567
+ "Analyze this physics image. What concepts, diagrams, or equations do you see?",
568
+ openrouter_key
569
+ )
570
+ else:
571
+ image_analysis = analyze_image_local_fallback(
572
+ image,
573
+ "Analyze this physics image"
574
+ )
575
+
576
+
577
  #st.divider()
578
 
579
  # Media Input