Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -153,7 +153,7 @@ class ModelRegistry:
|
|
153 |
def __init__(self):
|
154 |
# HuggingFace Models
|
155 |
self.hf_models = {
|
156 |
-
"
|
157 |
"Nous-Hermes": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO", # works well
|
158 |
"Zephyr 7B": "HuggingFaceH4/zephyr-7b-beta", # works
|
159 |
"Phi-3.5 Mini": "microsoft/Phi-3.5-mini-instruct", # works but poor results
|
@@ -400,16 +400,16 @@ def send_to_model(prompt, model_selection, hf_model_choice, hf_custom_model, hf_
|
|
400 |
logging.info("send to model starting...")
|
401 |
|
402 |
if not prompt or not prompt.strip():
|
403 |
-
return "Error: No prompt provided", None
|
404 |
|
405 |
try:
|
406 |
logging.info("sending to model preparation.")
|
407 |
|
408 |
# Basic input validation
|
409 |
valid_selections = ["Clipboard only", "HuggingFace Inference", "Groq API",
|
410 |
-
|
411 |
if model_selection not in valid_selections:
|
412 |
-
return "Error: Invalid model selection", None
|
413 |
|
414 |
# Check environment API keys
|
415 |
env_api_keys = {
|
@@ -425,71 +425,45 @@ def send_to_model(prompt, model_selection, hf_model_choice, hf_custom_model, hf_
|
|
425 |
|
426 |
# Model-specific validation - check only required keys
|
427 |
if model_selection == "Groq API" and not groq_api_key:
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
return "Error: Groq API key required", None
|
432 |
|
433 |
elif model_selection == "OpenAI ChatGPT" and not openai_api_key:
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
return "Error: OpenAI API key required", None
|
438 |
|
439 |
elif model_selection == "GLHF API" and not glhf_api_key:
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
return "Error: GLHF API key required", None
|
444 |
-
|
445 |
-
# Try implementation
|
446 |
-
try:
|
447 |
-
logging.info("calling send_to_model_impl.")
|
448 |
-
|
449 |
-
# Use rate limits only with environment API keys
|
450 |
-
use_rate_limits = {
|
451 |
-
"Groq API": groq_api_key == env_api_keys["GROQ_API_KEY"],
|
452 |
-
"OpenAI ChatGPT": openai_api_key == env_api_keys["OPENAI_API_KEY"],
|
453 |
-
"Cohere API": cohere_api_key == env_api_keys["COHERE_API_KEY"],
|
454 |
-
"GLHF API": glhf_api_key == env_api_keys["GLHF_API_KEY"]
|
455 |
-
}.get(model_selection, False)
|
456 |
-
|
457 |
-
summary, download_file = send_to_model_impl(
|
458 |
-
prompt=prompt.strip(),
|
459 |
-
model_selection=model_selection,
|
460 |
-
hf_model_choice=hf_model_choice,
|
461 |
-
hf_custom_model=hf_custom_model,
|
462 |
-
hf_api_key=hf_api_key,
|
463 |
-
groq_model_choice=groq_model_choice,
|
464 |
-
groq_api_key=groq_api_key,
|
465 |
-
openai_api_key=openai_api_key,
|
466 |
-
openai_model_choice=openai_model_choice,
|
467 |
-
cohere_api_key=cohere_api_key or env_api_keys["COHERE_API_KEY"],
|
468 |
-
cohere_model=cohere_model,
|
469 |
-
glhf_api_key=glhf_api_key,
|
470 |
-
glhf_model=glhf_model,
|
471 |
-
glhf_custom_model=glhf_custom_model,
|
472 |
-
use_rate_limits=use_rate_limits
|
473 |
-
)
|
474 |
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
486 |
|
487 |
except Exception as e:
|
488 |
-
error_msg = str(e)
|
489 |
-
if not error_msg:
|
490 |
-
error_msg = "Unknown error occurred"
|
491 |
logging.error(f"Error in send_to_model: {error_msg}")
|
492 |
-
return f"Error: {error_msg}", None
|
493 |
finally:
|
494 |
logging.info("send to model completed.")
|
495 |
|
@@ -604,7 +578,7 @@ def send_to_model_impl(prompt, model_selection, hf_model_choice, hf_custom_model
|
|
604 |
f.write(summary)
|
605 |
return summary, f.name
|
606 |
|
607 |
-
return summary,
|
608 |
|
609 |
except Exception as e:
|
610 |
error_msg = str(e)
|
@@ -986,7 +960,8 @@ with gr.Blocks(css="""
|
|
986 |
hf_model = gr.Dropdown(
|
987 |
choices=list(model_registry.hf_models.keys()),
|
988 |
label="🔧 HuggingFace Model",
|
989 |
-
value="
|
|
|
990 |
)
|
991 |
hf_custom_model = gr.Textbox( # This needs to be defined before being used
|
992 |
label="Custom Model ID",
|
@@ -1230,7 +1205,7 @@ with gr.Blocks(css="""
|
|
1230 |
gr.update(visible=False), # cohere_options
|
1231 |
gr.update(visible=False), # glhf_options
|
1232 |
gr.update(value=ctx_size), # context_size
|
1233 |
-
gr.Dropdown(choices=model_choices, value="
|
1234 |
]
|
1235 |
elif choice == "Groq API":
|
1236 |
model_choices = list(model_registry.groq_models.keys())
|
@@ -1446,9 +1421,9 @@ with gr.Blocks(css="""
|
|
1446 |
glhf_custom_model
|
1447 |
],
|
1448 |
outputs=[
|
1449 |
-
clipboard_status, #
|
1450 |
-
summary_output,
|
1451 |
-
download_summary
|
1452 |
]
|
1453 |
)
|
1454 |
|
|
|
153 |
def __init__(self):
|
154 |
# HuggingFace Models
|
155 |
self.hf_models = {
|
156 |
+
"Mistral 7B": "mistralai/Mistral-7B-Instruct-v0.3", # works well
|
157 |
"Nous-Hermes": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO", # works well
|
158 |
"Zephyr 7B": "HuggingFaceH4/zephyr-7b-beta", # works
|
159 |
"Phi-3.5 Mini": "microsoft/Phi-3.5-mini-instruct", # works but poor results
|
|
|
400 |
logging.info("send to model starting...")
|
401 |
|
402 |
if not prompt or not prompt.strip():
|
403 |
+
return gr.HTML(""), "Error: No prompt provided", None
|
404 |
|
405 |
try:
|
406 |
logging.info("sending to model preparation.")
|
407 |
|
408 |
# Basic input validation
|
409 |
valid_selections = ["Clipboard only", "HuggingFace Inference", "Groq API",
|
410 |
+
"OpenAI ChatGPT", "Cohere API", "GLHF API"]
|
411 |
if model_selection not in valid_selections:
|
412 |
+
return gr.HTML(""), "Error: Invalid model selection", None
|
413 |
|
414 |
# Check environment API keys
|
415 |
env_api_keys = {
|
|
|
425 |
|
426 |
# Model-specific validation - check only required keys
|
427 |
if model_selection == "Groq API" and not groq_api_key:
|
428 |
+
groq_api_key = env_api_keys.get("GROQ_API_KEY")
|
429 |
+
if not groq_api_key:
|
430 |
+
return gr.HTML(""), "Error: Groq API key required", None
|
|
|
431 |
|
432 |
elif model_selection == "OpenAI ChatGPT" and not openai_api_key:
|
433 |
+
openai_api_key = env_api_keys.get("OPENAI_API_KEY")
|
434 |
+
if not openai_api_key:
|
435 |
+
return gr.HTML(""), "Error: OpenAI API key required", None
|
|
|
436 |
|
437 |
elif model_selection == "GLHF API" and not glhf_api_key:
|
438 |
+
glhf_api_key = env_api_keys.get("GLHF_API_KEY")
|
439 |
+
if not glhf_api_key:
|
440 |
+
return gr.HTML(""), "Error: GLHF API key required", None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
441 |
|
442 |
+
# Call the implementation function
|
443 |
+
clipboard_status, summary, download_file = send_to_model_impl(
|
444 |
+
prompt=prompt.strip(),
|
445 |
+
model_selection=model_selection,
|
446 |
+
hf_model_choice=hf_model_choice,
|
447 |
+
hf_custom_model=hf_custom_model,
|
448 |
+
hf_api_key=hf_api_key,
|
449 |
+
groq_model_choice=groq_model_choice,
|
450 |
+
groq_api_key=groq_api_key,
|
451 |
+
openai_api_key=openai_api_key,
|
452 |
+
openai_model_choice=openai_model_choice,
|
453 |
+
cohere_api_key=cohere_api_key or env_api_keys.get("COHERE_API_KEY"),
|
454 |
+
cohere_model=cohere_model,
|
455 |
+
glhf_api_key=glhf_api_key,
|
456 |
+
glhf_model=glhf_model,
|
457 |
+
glhf_custom_model=glhf_custom_model,
|
458 |
+
use_rate_limits=False # Adjust based on your needs
|
459 |
+
)
|
460 |
+
|
461 |
+
return clipboard_status, summary, download_file
|
462 |
|
463 |
except Exception as e:
|
464 |
+
error_msg = str(e) or "Unknown error occurred"
|
|
|
|
|
465 |
logging.error(f"Error in send_to_model: {error_msg}")
|
466 |
+
return gr.HTML(f"Error: {error_msg}"), f"Error: {error_msg}", None
|
467 |
finally:
|
468 |
logging.info("send to model completed.")
|
469 |
|
|
|
578 |
f.write(summary)
|
579 |
return summary, f.name
|
580 |
|
581 |
+
return gr.HTML(""), summary, download_file
|
582 |
|
583 |
except Exception as e:
|
584 |
error_msg = str(e)
|
|
|
960 |
hf_model = gr.Dropdown(
|
961 |
choices=list(model_registry.hf_models.keys()),
|
962 |
label="🔧 HuggingFace Model",
|
963 |
+
value="Mistral 7B",
|
964 |
+
allow_custom_value=True
|
965 |
)
|
966 |
hf_custom_model = gr.Textbox( # This needs to be defined before being used
|
967 |
label="Custom Model ID",
|
|
|
1205 |
gr.update(visible=False), # cohere_options
|
1206 |
gr.update(visible=False), # glhf_options
|
1207 |
gr.update(value=ctx_size), # context_size
|
1208 |
+
gr.Dropdown(choices=model_choices, value="Mistral 7B") # Update default value
|
1209 |
]
|
1210 |
elif choice == "Groq API":
|
1211 |
model_choices = list(model_registry.groq_models.keys())
|
|
|
1421 |
glhf_custom_model
|
1422 |
],
|
1423 |
outputs=[
|
1424 |
+
clipboard_status, # HTML component for clipboard status
|
1425 |
+
summary_output, # Textbox for summary
|
1426 |
+
download_summary # File component for download
|
1427 |
]
|
1428 |
)
|
1429 |
|