admin08077 commited on
Commit
802cb33
·
verified ·
1 Parent(s): 70e64fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -2,40 +2,38 @@ import gradio as gr
2
  from google import genai
3
  import os
4
 
5
- # Get API key from environment variable (set this in Hugging Face Secrets)
6
  API_KEY = os.getenv("GEMINI_API_KEY")
7
 
8
  if not API_KEY:
9
- raise EnvironmentError("Missing GEMINI_API_KEY. Set it in Hugging Face Spaces → Secrets.")
10
 
11
- # Initialize the Gemini client
12
  client = genai.Client(api_key=API_KEY)
13
 
14
- # Load Gemini model
15
- model = client.models.get("models/gemini-2.0-flash")
16
 
17
- # Translation function
18
  def sober_up(drunk_text):
19
  if not drunk_text.strip():
20
  return "Please enter a message."
21
 
22
  prompt = f"Translate this drunk message into a sober, coherent version: '{drunk_text}'"
23
-
24
  try:
25
  response = model.generate_content(contents=prompt)
26
  return response.text
27
  except Exception as e:
28
  return f"Error: {e}"
29
 
30
- # Gradio Interface
31
  demo = gr.Interface(
32
  fn=sober_up,
33
- inputs=gr.Textbox(lines=4, placeholder="Paste your chaotic, drunk text here..."),
34
  outputs="text",
35
  title="🍺 SoberUp Translator",
36
- description="AI-powered translator for decoding drunk messages into sober, coherent statements using Gemini Flash."
37
  )
38
 
39
- # Launch app
40
  if __name__ == "__main__":
41
  demo.launch()
 
2
  from google import genai
3
  import os
4
 
5
+ # Get API key from Hugging Face secrets
6
  API_KEY = os.getenv("GEMINI_API_KEY")
7
 
8
  if not API_KEY:
9
+ raise EnvironmentError("Missing GEMINI_API_KEY. Make sure it's set in the Hugging Face Secrets.")
10
 
11
+ # Initialize Gemini Client
12
  client = genai.Client(api_key=API_KEY)
13
 
14
+ # Use correct keyword argument for model name
15
+ model = client.models.get(name="models/gemini-2.0-flash")
16
 
 
17
  def sober_up(drunk_text):
18
  if not drunk_text.strip():
19
  return "Please enter a message."
20
 
21
  prompt = f"Translate this drunk message into a sober, coherent version: '{drunk_text}'"
22
+
23
  try:
24
  response = model.generate_content(contents=prompt)
25
  return response.text
26
  except Exception as e:
27
  return f"Error: {e}"
28
 
29
+ # Gradio interface
30
  demo = gr.Interface(
31
  fn=sober_up,
32
+ inputs=gr.Textbox(lines=4, placeholder="Type or paste your drunk text here..."),
33
  outputs="text",
34
  title="🍺 SoberUp Translator",
35
+ description="AI-powered Gemini app that translates your drunk ramblings into clean, sober text."
36
  )
37
 
 
38
  if __name__ == "__main__":
39
  demo.launch()