Udyan commited on
Commit
1ddb113
·
verified ·
1 Parent(s): 233db0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -1,29 +1,26 @@
1
  import gradio as gr
2
- from openai import OpenAI
3
- import os
4
 
5
- client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
 
 
6
 
7
  def chat(message):
8
- try:
9
- response = client.chat.completions.create(
10
- model="gpt-4o-mini",
11
- messages=[
12
- {"role": "system", "content": "You are a helpful assistant."},
13
- {"role": "user", "content": message}
14
- ]
15
- )
16
- return response.choices[0].message.content
17
 
18
- except Exception as e:
19
- return f"API error: {str(e)}"
 
 
 
 
 
20
 
21
  iface = gr.Interface(
22
  fn=chat,
23
- inputs=gr.Textbox(label="Ask something"),
24
  outputs="text",
25
  title="AI Assistant",
26
- description="Ask anything"
27
  )
28
 
29
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
 
3
 
4
+ client = InferenceClient(
5
+ model="mistralai/Mistral-7B-Instruct-v0.2"
6
+ )
7
 
8
  def chat(message):
 
 
 
 
 
 
 
 
 
9
 
10
+ response = client.text_generation(
11
+ message,
12
+ max_new_tokens=200
13
+ )
14
+
15
+ return response
16
+
17
 
18
  iface = gr.Interface(
19
  fn=chat,
20
+ inputs="text",
21
  outputs="text",
22
  title="AI Assistant",
23
+ description="Free AI assistant using Hugging Face"
24
  )
25
 
26
+ iface.launch()