-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ModuleNotFoundError: No module named '__main__' with auto-reloading #5468
Comments
hi I wish to contribute to the issue |
Contributions are welcom @kshitiz305 ! |
I'm encountering this same bug. import langchain_helper as lch def reclaim_mem():
reclaim_mem() def make_folder(): #take input from user and pass to langchain helper, which needs to be renamed, it's got no langchain in it
demo = gr.Blocks()
if name == 'main': CLI shows : Traceback (most recent call last): |
I'm not sure about rye (what the original issue comment mentions) but I think this problem is fixed in the v4 branch to be released in about two weeks. |
The issues persists in gradio==4.0.2 @freddyaboulton |
Can you share the code @cheulyop ? Will take a look - thanks! |
Sure. Here's a snippet. Let me know if this isn't enough, @freddyaboulton Thanks. import gradio as gr
from loguru import logger
log_path = f"logs/{datetime.now().strftime('%Y-%m-%d')}.log"
logger.add(log_path, rotation="1 day", retention="6 months", level="INFO")
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
chatbot = gr.Chatbot(show_copy_button=True, height=750)
msg = gr.Textbox(label="User message.", placeholder="Type here...")
clear = gr.ClearButton(
[
msg,
chatbot,
],
value="New Conversation",
)
if not IS_PROD:
with gr.Column():
search_query = gr.Textbox(
label="Search query",
interactive=False,
)
search_results = gr.Code(
label="Search results", language="json", interactive=False, lines=10
)
else:
search_query = None
search_results = None
@logger.catch
def submit_handler(*args, **kwargs):
return user_msg_submitted(*args, **kwargs)
msg.submit(
submit_handler,
[msg, chatbot],
[msg, chatbot, search_query, search_results] if not IS_PROD else [msg, chatbot],
)
clear.click()
if __name__ == "__main__":
# demo.queue()
logger.info("Starting demo server...")
demo.launch(
share=os.getenv("SHARE", "False") == "True",
server_name=os.getenv("SERVER_NAME", "127.0.0.1"),
server_port=int(os.getenv("SERVER_PORT", "7860")),
)
logger.info("Demo server stopped.") |
@freddyaboulton freddyaboulton Can confirm this issue is fixed for me with 4.0, thank you! EDIT: Update, actually this is technically working but seems to continue running in the background and in a new updated run. Example of first run with no code changes : Prompt Template : You are an intelligent and very good writer of fantasy fiction that uses a diverse and wide ranging vocabulary. Write a very concise, visually descriptive, detailed and colorful paragraph description of a Eagle Headed, lion bodied, winged griffin, include description of its body, face, and limbs, it is with a dark skinned female knight mounted on it's back and size Large at on a castle wall overlooking an army of monsters . The with a dark skinned female knight mounted on it's back Eagle Headed, lion bodied, winged griffin The majestic eagle-headed, lion-bodied, winged griffin stood tall and proud on the castle wall, its regal presence casting a shadow over the army of monsters below. Its body was strong and muscular, resembling a lion's, with a thick, shaggy mane that rippled in the wind. Its wings, wide and powerful, stretched out from its back, ready to take flight at a moment's notice. Its head, adorned with piercing, golden eyes, was that of an eagle, sharp and cunning, scanning the horizon for potential threats. Its limbs were long and agile, ending in razor-sharp talons, perfect for grasping and tearing. Its torso was sleek and streamlined, a testament to its incredible strength and agility. The griffin's appendages, both wings and talons, were a sight to behold, their power and grace a testament to its divine origin. Atop the magnificent creature stood a dark-skinned female knight, her armor gleaming in the sunlight, her sword held high, ready to face the monstrous horde below. Together, the griffin and knight formed an unstoppable force, their bond unbreakable as they soared over the castle wall, casting a shadow of fear over the enemy below. This is after updating code. It starts immediately calling the LLM, and does it in a loop, seems like once for each time I've updated the code. Refreshing the browser window seems to resolve this after it's complete the loop. Prompt Template : You are an intelligent and very good writer of fantasy fiction that uses a diverse and wide ranging vocabulary. Write a very concise, visually descriptive, detailed and colorful paragraph description of a A feminine armored orc, include description of its body, face, and limbs, it is astride a golden and white eagle headed griffin and size Large at . The astride a golden and white eagle headed griffin A feminine armored orc In the heart of the battlefield, a magnificent sight unfolds: a feminine armored Orc, standing tall and proud at a size Large. Her body, a testament to her strength and resilience, is encased in gleaming, intricately designed armor that shimmers in the sunlight. Her head, adorned with a helmet that bears the insignia of her clan, is a perfect blend of ferocity and grace, with piercing, almond-shaped eyes that seem to see right through you. Her limbs, powerful and muscular, end in sharp, deadly claws that can tear through even the toughest of foes. Her torso, broad and imposing, houses a heart full of courage and determination. As she astride her loyal steed, a golden and white eagle-headed griffin, she commands an aura of dominance and authority. The griffin, with its majestic wings spread wide, soars gracefully through the chaos of the battlefield, its eyes locked with those of its rider. The bond between the two is palpable, a testament to their unbreakable trust and loyalty. Together, they cut through the enemy ranks with ease, leaving a trail of destruction in their wake. This feminine armored Orc, a force to be reckoned with, stands as a symbol of strength, courage, and unity, her presence alone enough to strike fear into the hearts of her adversaries. As she charges into battle, her golden and white eagle-headed griffin by her side, the battlefield trembles with anticipation of the carnage to come. Code that includes gradio
|
I encounter this error too |
I am facing the same issue |
Hi team - I am definitely running into the same issue as well. Is there anything we can do to accelerate the fix for this? As far as I can tell, auto reloading just does not work because of this issue and renders the "gradio cc dev" completely pointless. I am not using rye and just doing gradio==4.8.0 Thank you. |
Same issue here! Gradio version: 4.9.0 |
@abidlabs Hey this bug has existed in Gradio for quiet a while and it's still present in the latest version. It makes continues development really annoying because you have to rerun the app which each ui change. |
Sorry about that! cc @freddyaboulton who I believe is looking into this issue |
Hi @arian81 , @joaomorossini , @sangv, @MohamedAliRashad , and others! First of all, apologies for the delay. I have not been able to reproduce this issue in a fresh environment with gradio 4.10.0 installed (the latest version). Here I am running the code @cheulyop shared. I am able to make a change and have the app reload automatically without restarting the whole app. reload_desktop.movI really want to fix this but it will be difficult if I can't reproduce the problem. Can you do the following to help me figure out what's happening?
Thank you for your help in advanced! |
Thanks @freddyaboulton for looking into this. I can confirm that I still have this issue with the versions shown below. pip list | grep 'gradio' Followed by: And finally this: Changed detected in: {my_home_dir_location}/demo/app.py Reloading demo.app failed with the following exception: ModuleNotFoundError: No module named 'main' |
any progress or ETA on the issue? |
Running version from #6983 I finally got a traceback of what's causing this issue. It's the
I can confirm not using dotenv package i.e not calling |
When hotreload the server the gradio==4.14.0 I receive the error
def configure_demo_interface():
with gr.Blocks() as demo:
chatbot = gr.Chatbot(
avatar_images=(
None,
(os.path.join(os.path.dirname(__file__), "images/doc.jpg")),
)
)
tts_output = gr.Audio()
msg = gr.Textbox()
gr.ClearButton([msg, chatbot])
msg.submit(run_text_prompt, [msg, chatbot], [msg, chatbot, tts_output])
asr = None
with gr.Row():
audio = gr.Audio(type="filepath")
button = gr.Button("Sent audio")
if audio is not None:
asr = ModelASR()
button.click(
asr.run_audio_prompt, [audio, chatbot], [audio, chatbot, tts_output]
)
return demo
log_file = create_logfile()
chat = chatPlugin(log_file)
configure_logging(log_file)
if __name__ == "__main__":
demo = configure_demo_interface()
demo.launch(server_name="0.0.0.0") ```
Run code by command
`gradio main.py` |
@sangv @joaomorossini @MohamedAliRashad Can you see what traceback you get with 4.14.0? @Nghiauet Please create the demo object outside the |
@freddyaboulton
|
yes confirm the same that @arian81 crashing when today, the issues persist with the versions
Code: import os
import autogen
import gradio as gr
from dotenv import load_dotenv
load_dotenv()
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
msg = gr.Textbox()
clear = gr.ClearButton([msg, chatbot])
def respond(message, chat_history):
# core.init_chat(message)
bot_message = "Hello Hello 1sqq2"
chat_history.append((message, bot_message))
print(chat_history)
return "", chat_history
msg.submit(respond, [msg, chatbot], [msg, chatbot])
demo.launch(server_port=8080) Command:
|
Not sure if this is fixable from gradio or is a dotenv bug but it seems for now not using dotenv during development will solve the issue. |
Potential fix in dotenv here: https://github.com/theskumar/python-dotenv/pulls |
This has been fixed in python-dotenv version 1.0.1! Adding a new env variable to a dotenv file is picked up by reload mode! Modifying a env variable is not. That's expected dotenv behavior, it doesn't overwrite env variables that are already set. Thanks for your patience everyone. |
Describe the bug
I’m using rye as a Python package management,here's the link of documention https://rye-up.com/
Auto-reloading by running
rye run gradio src/run.py
raised a ModuleNotFoundErrorHave you searched existing issues? 🔎
Reproduction
Screenshot
No response
Logs
Changes detected in: /Users/code/snaker/hello/src/run.py Reloading src.run failed with the following exception: ModuleNotFoundError: No module named '__main__'
System Info
Severity
Blocking usage of gradio
The text was updated successfully, but these errors were encountered: