privateuserh commited on
Commit
b7f1dfa
Β·
verified Β·
1 Parent(s): 5b2c723

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -20
app.py CHANGED
@@ -1,79 +1,106 @@
1
  # app.py on Hugging Face Space
 
2
  import gradio as gr
3
- import requests # Used for making HTTP requests to your backend
4
  import os
5
 
6
  # --- IMPORTANT ---
7
  # Replace this with your actual Cloudflare Worker URL after deployment.
8
  # You can also set this as a Hugging Face Space secret if you prefer.
9
  BACKEND_API_URL = os.getenv("BACKEND_API_URL", "https://your-worker-name.your-username.workers.dev")
10
- # Example: https://actor-llm-deepseek-backend.your-username.workers.dev
11
 
12
- # Store conversation history for context
13
  conversation_history = []
14
  current_script_in_session = ""
15
  current_character_in_session = ""
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  def get_actor_advice(user_query, script_input, character_name_input):
18
  global conversation_history, current_script_in_session, current_character_in_session
19
 
20
- # 1. Check if script or character changed to reset context
21
  if script_input != current_script_in_session or character_name_input != current_character_in_session:
22
- conversation_history = [] # Reset history
23
  current_script_in_session = script_input
24
  current_character_in_session = character_name_input
25
  gr.Warning("Script or character changed! Conversation context has been reset.")
26
 
27
- # 2. Prepare payload for the Cloudflare Worker
28
  payload = {
29
  "userQuery": user_query,
30
  "scriptContent": script_input,
31
  "characterName": character_name_input,
32
- "conversationHistory": conversation_history # Send current history
33
  }
34
 
35
  headers = {"Content-Type": "application/json"}
36
 
37
  try:
38
- # 3. Make HTTP POST request to your Cloudflare Worker
39
  response = requests.post(BACKEND_API_URL, json=payload, headers=headers)
40
- response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
41
 
42
  response_data = response.json()
43
  llm_response = response_data.get("response", "No advice received.")
44
 
45
- # 4. Update conversation history with user query and LLM response
46
  conversation_history.append({"role": "user", "content": user_query})
47
- conversation_history.append({"role": "actor", "content": llm_response})
48
 
49
  return llm_response
50
  except requests.exceptions.RequestException as e:
51
  print(f"Error communicating with backend: {e}")
52
- return f"Error connecting to the backend. Please ensure the backend is deployed and accessible. Details: {e}"
53
  except Exception as e:
54
  print(f"An unexpected error occurred: {e}")
55
  return f"An unexpected error occurred: {e}"
56
 
57
- # --- Frontend UI with Gradio ---
58
  with gr.Blocks() as demo:
59
- gr.Markdown("# Actor's LLM")
60
- gr.Markdown("Enter your script and ask for acting advice for your character. The AI will remember past queries in the current session. This session is Sponsored by my AI Avatar, SM+ and Astral Nexus Studio")
61
 
62
  with gr.Row():
63
  with gr.Column():
64
  script_input = gr.Textbox(
65
  label="Paste Your Script Here",
66
  lines=10,
67
- placeholder="[Scene: A vibrant California beach...]\nSUSAN: (Whispering) 'I can't believe this...'"
 
 
68
  )
69
  character_name_input = gr.Textbox(
70
  label="Your Character's Name",
71
- placeholder="Susan Summers"
72
  )
73
- # Photo customization placeholder (as discussed, for UI or future multimodal)
74
  photo_upload = gr.Image(
75
  label="Upload Actor Photo (for UI personalization)",
76
- type="pil", # Pillow image object
77
  sources=["upload"],
78
  interactive=True
79
  )
@@ -82,7 +109,7 @@ with gr.Blocks() as demo:
82
  with gr.Column():
83
  query_input = gr.Textbox(
84
  label="Ask for Acting Advice",
85
- placeholder="e.g., How should Susan deliver her line 'Everyone looks so good...' to convey happiness?",
86
  lines=3
87
  )
88
  submit_btn = gr.Button("Get Advice")
 
1
  # app.py on Hugging Face Space
2
+
3
  import gradio as gr
4
+ import requests
5
  import os
6
 
7
  # --- IMPORTANT ---
8
  # Replace this with your actual Cloudflare Worker URL after deployment.
9
  # You can also set this as a Hugging Face Space secret if you prefer.
10
  BACKEND_API_URL = os.getenv("BACKEND_API_URL", "https://your-worker-name.your-username.workers.dev")
 
11
 
 
12
  conversation_history = []
13
  current_script_in_session = ""
14
  current_character_in_session = ""
15
 
16
+ # --- PASTE YOUR SCRIPT CONTENT HERE ---
17
+ ASTRAL_NEXUS_SCRIPT_CONTENT = """
18
+ **Astral Nexus (Backlot) - Public Showcase Script**
19
+
20
+ **Character:** ASTRAL (representing Astral Nexus Studio)
21
+
22
+ Good morning, aspiring storytellers, futurists, and dreamers! Welcome to a glimpse behind the cosmic curtain, right here at Astral Nexus Studio. We're often asked, "What *is* Astral Nexus?" And my answer is always the same: it's where the **human heart of creativity meets the limitless power of AI technology.** Our vision is simple, yet profound: we're forging an innovative media production hub, designed to propel storytelling far beyond the boundaries of Earth, into the infinite possibilities of space itself.
23
+
24
+ Think of it. We're not just making films or shows; we're launching narratives into the vast unknown, pushing the boundaries of cinematic imagination. Our mission? To develop and produce truly compelling sci-fi narratives across film, television, and digital platforms, all within a state-of-the-art facility that fosters both established and emerging talent.
25
+
26
+ While our exact location remains *undisclosed* for proprietary reasons, imagine a sprawling 5,000 square feet – and growing! – dedicated solely to the future of media. From the moment you approach our **gated Front Entrance**, secured with biometric and facial recognition, you know you're entering a place like no other.
27
+
28
+ Step into our **Lobby**, modern and sleek, alive with AI-powered displays showcasing our groundbreaking past productions and thrilling upcoming projects. We have five **private, soundproof offices** – sanctuaries for our writers, directors, and producers, outfitted with advanced tech for pure creative focus.
29
+
30
+ Then, there's the heart of physical creation: our **spacious Construction Area**. This is where imagination takes form, with 3D printers humming, CNC machines shaping, and dedicated materials storage. And just beyond that, our **Filming Backlot** – a versatile outdoor space with massive green screens, incredible landscaped areas, and pre-constructed set pieces ready for any sci-fi environment you can dream up.
31
+
32
+ Of course, even cosmic explorers need to refuel! Our **Break Room & Vendor Area** is a comfortable, inviting space, focusing on healthy eating, with rotating food trucks, a coffee bar, and lounge areas. It's designed for connection, for collaboration – for the human element that drives everything.
33
+
34
+ Now, let's talk about the **role of AI**. Many ask, "Are AI actors replacing human talent?" And our answer is a resounding *no*. At Astral Nexus, AI isn't here to replace; it's here to **empower**. Think of it as a super-talented co-star and an invaluable crew member.
35
+
36
+ Our **AI-powered production assistant, "Nexus,"** is the backbone of our studio operations. Nexus handles everything from intricate **scheduling and budgeting** to deep **script analysis** and complex **logistics**. It streamlines our workflows, maximizes efficiency, and frees our human creatives to focus on what they do best: *telling incredible stories*.
37
+
38
+ Imagine designing a set. With our **virtual reality set design**, filmmakers can prototype and refine entire environments *before* a single physical piece is constructed. We use **advanced motion capture** for incredibly realistic CGI animation and character creation – whether that's a fantastical alien or a perfectly rendered stunt double. And our **post-production suite** is equipped with cutting-edge editing software, enhanced by AI-powered tools for stunning sound design, seamless visual effects, and precise color grading.
39
+
40
+ So, when you see an AI character in an Astral Nexus production, understand that it's a meticulously crafted performance, brought to life through human artistry, enhanced by AI. It allows us to create characters and worlds that were previously impossible, opening up entirely new storytelling avenues for our **proprietary projects**, and for **independent and major film studios**, and **streaming platforms** who seek a dedicated sci-fi production facility with this advanced technology.
41
+
42
+ Our **competitive advantage** is clear: a unique, dedicated focus on the sci-fi genre, housed in facilities specifically built for it. It's the cutting-edge **AI technology integration** that enhances efficiency and storytelling without sacrificing soul. It’s our **collaborative environment** that nurtures talent and sparks creative exchange. And yes, it's our **prime location**, giving us access to the best industry professionals and resources.
43
+
44
+ Astral Nexus Studios isn't just a studio; it's a promise. A promise to revolutionize sci-fi storytelling by fusing human creativity with the most advanced technology available. This is where captivating narratives are launched into the vast unknown. This is where we push the boundaries of cinematic imagination, one groundbreaking story at a time. Thank you.
45
+ """
46
+
47
  def get_actor_advice(user_query, script_input, character_name_input):
48
  global conversation_history, current_script_in_session, current_character_in_session
49
 
 
50
  if script_input != current_script_in_session or character_name_input != current_character_in_session:
51
+ conversation_history = []
52
  current_script_in_session = script_input
53
  current_character_in_session = character_name_input
54
  gr.Warning("Script or character changed! Conversation context has been reset.")
55
 
 
56
  payload = {
57
  "userQuery": user_query,
58
  "scriptContent": script_input,
59
  "characterName": character_name_input,
60
+ "conversationHistory": conversation_history
61
  }
62
 
63
  headers = {"Content-Type": "application/json"}
64
 
65
  try:
 
66
  response = requests.post(BACKEND_API_URL, json=payload, headers=headers)
67
+ response.raise_for_status()
68
 
69
  response_data = response.json()
70
  llm_response = response_data.get("response", "No advice received.")
71
 
 
72
  conversation_history.append({"role": "user", "content": user_query})
73
+ conversation_history.append({"role": "assistant", "content": llm_response}) # Keep 'assistant' role for LLM responses
74
 
75
  return llm_response
76
  except requests.exceptions.RequestException as e:
77
  print(f"Error communicating with backend: {e}")
78
+ return f"Error connecting to the backend. Details: {e}"
79
  except Exception as e:
80
  print(f"An unexpected error occurred: {e}")
81
  return f"An unexpected error occurred: {e}"
82
 
83
+
84
  with gr.Blocks() as demo:
85
+ gr.Markdown("# Actor's LLM Assistant")
86
+ gr.Markdown("Enter your script and ask for acting advice for your character. The AI will remember past queries in the current session.")
87
 
88
  with gr.Row():
89
  with gr.Column():
90
  script_input = gr.Textbox(
91
  label="Paste Your Script Here",
92
  lines=10,
93
+ # --- SET THE DEFAULT SCRIPT CONTENT HERE ---
94
+ value=ASTRAL_NEXUS_SCRIPT_CONTENT,
95
+ interactive=True # Allow users to edit or replace it
96
  )
97
  character_name_input = gr.Textbox(
98
  label="Your Character's Name",
99
+ placeholder="ASTRAL" # Set a relevant placeholder
100
  )
 
101
  photo_upload = gr.Image(
102
  label="Upload Actor Photo (for UI personalization)",
103
+ type="pil",
104
  sources=["upload"],
105
  interactive=True
106
  )
 
109
  with gr.Column():
110
  query_input = gr.Textbox(
111
  label="Ask for Acting Advice",
112
+ placeholder="e.g., How should ASTRAL deliver the line 'human heart of creativity meets the limitless power of AI technology' to convey both wonder and confidence?",
113
  lines=3
114
  )
115
  submit_btn = gr.Button("Get Advice")